private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(InteropMethods.CallNextHookEx(HookId, nCode, wParam, lParam)); } var hookStruct = (InteropValues.MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(InteropValues.MOUSEHOOKSTRUCT)); StatusChanged?.Invoke(null, new MouseHookEventArgs { MessageType = (MouseHookMessageType)wParam, Point = new InteropValues.POINT(hookStruct.pt.X, hookStruct.pt.Y) }); return(InteropMethods.CallNextHookEx(HookId, nCode, wParam, lParam)); }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { if (wParam == KeyDownIntPtr) { var virtualKey = Marshal.ReadInt32(lParam); if (VirtualKey != virtualKey) { VirtualKey = virtualKey; KeyDown?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false)); } } else if (wParam == SyskeyDownIntPtr) { var virtualKey = Marshal.ReadInt32(lParam); if (VirtualKey != virtualKey) { VirtualKey = virtualKey; KeyDown?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true)); } } else if (wParam == KeyUpIntPtr) { var virtualKey = Marshal.ReadInt32(lParam); VirtualKey = -1; KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false)); } else if (wParam == SyskeyUpIntPtr) { var virtualKey = Marshal.ReadInt32(lParam); VirtualKey = -1; KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true)); } } return(InteropMethods.CallNextHookEx(HookId, nCode, wParam, lParam)); }