/// <summary> /// Low level hook func that is invoked by windows whenever there is a /// global keyboard event /// </summary> /// <param name="nCode">the code</param> /// <param name="wParam">wParam</param> /// <param name="lParam">lParam</param> /// <returns>-1 if handled, otherwise if not handled</returns> public int HookProc(int nCode, IntPtr wParam, IntPtr lParam) { bool handled = false; if (nCode >= 0) { var keyboardLLHookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); var wmKeyboard = (KeyboardWParam)wParam; notifyEvent(wmKeyboard, keyboardLLHookStruct, ref handled); } return(handled ? -1 : User32Interop.CallNextHookEx(_hookHandle, nCode, wParam, lParam)); }