private int HookProc(int code, int wParam, int lParam) { if (code < 0) { return(KeyboardHook.CallNextHookEx(this._hookId, code, wParam, lParam)); } if (wParam == 256 || wParam == 260) { Keys keys = (Keys)Marshal.ReadInt32((IntPtr)lParam); if (this.TargetedKeys.Contains(keys)) { Action <Keys> keyDown = this.KeyDown; if (keyDown != null) { keyDown(keys); } } } return(KeyboardHook.CallNextHookEx(this._hookId, code, wParam, lParam)); }
public void Dispose() { KeyboardHook.UnhookWindowsHookEx(this._hookId); }
private KeyboardHook() { this.hookCallback = new KeyboardHook.CallbackDelegate(this.HookProc); this._hookId = KeyboardHook.SetWindowsHookEx(13, this.hookCallback, 0, 0); this.TargetedKeys = new List <Keys>(); }
public HotkeyManager(KeyboardHook hook) { _hook = hook; }