
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Using the Windows Keyboard Hook
|
529
you could prevent the user from using specific keys (such as the Windows key) from
within your application.
Solution
The Windows Forms application shown in Example 9-13 uses the WH_KEYBOARD Win-
dows hook.
Example 9-13. Using the Windows keyboard hook
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
// Required designer variable
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
public Form1( )
{
// Required for Windows Form Designer support
InitializeComponent( );
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose( );
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent( )
{
this.button1 = new System.Windows.Forms.Button( );
this.button2 = new System.Windows.Forms.Button( );
this.textBox1 = new System.Windows.Forms.TextBox( );