private IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { try { return(HookCallbackInner(nCode, wParam, lParam)); } catch (Exception e) { Logger.Error("There was some error somewhere..."); Logger.Error(e); } return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam)); }
private IntPtr HookCallbackInner(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { if (wParam == (IntPtr)InterceptKeys.WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); KeyDown?.Invoke(this, new RawKeyEventArgs(vkCode, false)); } else if (wParam == (IntPtr)InterceptKeys.WM_KEYUP) { int vkCode = Marshal.ReadInt32(lParam); KeyUp?.Invoke(this, new RawKeyEventArgs(vkCode, false)); } } return(InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam)); }
public void Dispose() { InterceptKeys.UnhookWindowsHookEx(hookId); }
public GlobalKeyboardListener() { callback = HookCallback; hookId = InterceptKeys.SetHook(callback); }