private IntPtr KeyboardHookDelegate(int code, IntPtr wParam, IntPtr lParam) { if (code >= 0) { if (wParam == (IntPtr)WM_KEYDOWN) { var vkCode = (Keys)Marshal.ReadInt32(lParam); var keyEventArgs = new KeyEventArgs(vkCode); OnKeyDown(keyEventArgs); } else if (wParam == (IntPtr)WM_KEYUP) { var vkCode = (Keys)Marshal.ReadInt32(lParam); var keyEventArgs = new KeyEventArgs(vkCode); OnKeyUp(keyEventArgs); } } return(WindowsHookHelper.CallNextHookEx(_keyboardHandle, code, wParam, lParam)); }
private IntPtr KeyboardHookDelegate(int code, IntPtr wParam, IntPtr lParam) { if (code >= 0) { var arg = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); MouseEventArgs mouseEventArgs; switch ((int)wParam) { case WM_MOUSEMOVE: mouseEventArgs = new MouseEventArgs(MouseButtons.None, 0, arg.pt.x, arg.pt.y, 0); OnMouseMoved(mouseEventArgs); break; case WM_MOUSEWHEEL: var delta = 0; if (arg.mouseData > 0) { delta = 1; } else if (arg.mouseData < 0) { delta = -1; } mouseEventArgs = new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta); OnMouseWheel(mouseEventArgs); break; case WM_LBUTTONDBLCLK: mouseEventArgs = new MouseEventArgs(MouseButtons.Left, 2, arg.pt.x, arg.pt.y, 0); OnMouseDoubleClicked(mouseEventArgs); break; case WM_RBUTTONDBLCLK: mouseEventArgs = new MouseEventArgs(MouseButtons.Right, 2, arg.pt.x, arg.pt.y, 0); OnMouseDoubleClicked(mouseEventArgs); break; case WM_MBUTTONDBLCLK: mouseEventArgs = new MouseEventArgs(MouseButtons.Middle, 2, arg.pt.x, arg.pt.y, 0); OnMouseDoubleClicked(mouseEventArgs); break; case WM_XBUTTONDBLCLK: mouseEventArgs = new MouseEventArgs(arg.mouseData == 1 ? MouseButtons.XButton1 : MouseButtons.XButton2, 2, arg.pt.x, arg.pt.y, 0); OnMouseDoubleClicked(mouseEventArgs); break; case WM_LBUTTONUP: mouseEventArgs = new MouseEventArgs(MouseButtons.Left, 1, arg.pt.x, arg.pt.y, 0); OnMouseClicked(mouseEventArgs); OnMouseUp(mouseEventArgs); break; case WM_RBUTTONUP: mouseEventArgs = new MouseEventArgs(MouseButtons.Right, 1, arg.pt.x, arg.pt.y, 0); OnMouseClicked(mouseEventArgs); OnMouseUp(mouseEventArgs); break; case WM_MBUTTONUP: mouseEventArgs = new MouseEventArgs(MouseButtons.Middle, 1, arg.pt.x, arg.pt.y, 0); OnMouseClicked(mouseEventArgs); OnMouseUp(mouseEventArgs); break; case WM_XBUTTONUP: mouseEventArgs = new MouseEventArgs(arg.mouseData == 1 ? MouseButtons.XButton1 : MouseButtons.XButton2, 1, arg.pt.x, arg.pt.y, 0); OnMouseClicked(mouseEventArgs); OnMouseUp(mouseEventArgs); break; case WM_LBUTTONDOWN: mouseEventArgs = new MouseEventArgs(MouseButtons.Left, 1, arg.pt.x, arg.pt.y, 0); OnMouseDown(mouseEventArgs); break; case WM_RBUTTONDOWN: mouseEventArgs = new MouseEventArgs(MouseButtons.Right, 1, arg.pt.x, arg.pt.y, 0); OnMouseDown(mouseEventArgs); break; case WM_MBUTTONDOWN: mouseEventArgs = new MouseEventArgs(MouseButtons.Middle, 1, arg.pt.x, arg.pt.y, 0); OnMouseDown(mouseEventArgs); break; case WM_XBUTTONDOWN: mouseEventArgs = new MouseEventArgs(arg.mouseData == 1 ? MouseButtons.XButton1 : MouseButtons.XButton2, 1, arg.pt.x, arg.pt.y, 0); OnMouseDown(mouseEventArgs); break; } } return(WindowsHookHelper.CallNextHookEx(_mouseHandle, code, wParam, lParam)); }