private static bool HandleMouseEvent(NativeMouseEvent eventCode, MousePosition pos, int wheelDelta) { switch (eventCode) { case NativeMouseEvent.WM_MOUSEMOVE: OnMouseMove?.Invoke(pos); return(true); case NativeMouseEvent.WM_LBUTTONDOWN: OnMouseLeftDown?.Invoke(pos); return(true); case NativeMouseEvent.WM_LBUTTONUP: OnMouseLeftUp?.Invoke(pos); return(true); case NativeMouseEvent.WM_RBUTTONDOWN: OnMouseRightDown?.Invoke(pos); return(true); case NativeMouseEvent.WM_RBUTTONUP: OnMouseRightUp?.Invoke(pos); return(true); case NativeMouseEvent.WM_MOUSEWHEEL: OnMouseWheel?.Invoke(pos, wheelDelta); return(true); default: return(false); } }
private static int HandleLowLevelHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(Win32API.CallNextHookEx(hookPtr, code, wParam, lParam)); } NativeMouseEvent eventCode = unchecked ((NativeMouseEvent)wParam); MSLLHOOKSTRUCT data = MSLLHOOKSTRUCT.CreateFromPtr(lParam); MousePosition pos = new MousePosition { x = data.pt.x, y = data.pt.y }; int wheelDelta = unchecked ((short)((long)data.mouseData >> 16)); if (HandleMouseEvent(eventCode, pos, wheelDelta) && InterceptMessages) { return(1); } else { return(Win32API.CallNextHookEx(hookPtr, 0, wParam, lParam)); } }