public int HookProc(int code, int wParam, ref WinAPI.KeyboardHookStruct lParam) { // we only look for keyups and downs if (code >= 0 && (wParam == WinAPI.WM_KEYDOWN || wParam == WinAPI.WM_SYSKEYDOWN || wParam == WinAPI.WM_KEYUP || wParam == WinAPI.WM_SYSKEYUP)) { // create out async handler and call it. if we needed to return "handled" chage this to ".Invoke()" KeyboardHookEventArgs kea = new KeyboardHookEventArgs((Keys)lParam.vkCode); m_hookedAsync.BeginInvoke(wParam, kea, null, null); } return WinAPI.CallNextHookEx(m_hook, code, wParam, ref lParam); }
public static extern IntPtr SetWindowsHookEx(WinAPI.HookType code, KeyboardHookProc callback, IntPtr hInstance, int threadId);