/// <summary> /// Initializes a new instance of the <see cref="GlobalKeyboardListener" /> class and installs the keyboard hook.</summary> public GlobalKeyboardListener() { IntPtr hInstance = WinAPI.LoadLibrary("User32"); _hook = hookProc; // don’t remove this or the garbage collector will collect it while the global hook still tries to access it _hHook = WinAPI.SetWindowsHookEx(WinAPI.WH_KEYBOARD_LL, _hook, IntPtr.Zero, 0); }
/// <summary> /// Occurs when one of the hooked keys is pressed and released /// </summary> //public event KeyEventHandler KeyPressed; /// <summary> /// Initializes a new instance of the <see cref="globalKeyboardHook"/> class and installs the keyboard hook. /// </summary> public GlobalKeyboardHook() { keyboardHookProc = HookCallback; Hook(); }
public static extern IntPtr SetWindowsHookEx(int idHook, WinAPI.KeyboardHookProc callback, IntPtr hInstance, uint threadId);