示例#1
0
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (wParam == (IntPtr)WM_MOUSEMOVE)
                {
                    if (MouseMoveEvent != null)
                    {
                        MouseMoveEvent(this, GetMousePoint(lParam));
                    }
                }
                else
                {
                    switch ((Int32)wParam)
                    {
                    case WM_LBUTTONDOWN:
                        if (MouseDownEvent != null)
                        {
                            MouseDownEvent(this, GetMousePoint(lParam), MouseButtons.Left);
                        }
                        break;

                    case WM_LBUTTONUP:
                        if (MouseUpEvent != null)
                        {
                            MouseUpEvent(this, GetMousePoint(lParam), MouseButtons.Left);
                        }
                        break;

                    case WM_RBUTTONDOWN:
                        if (MouseDownEvent != null)
                        {
                            MouseDownEvent(this, GetMousePoint(lParam), MouseButtons.Right);
                        }
                        break;

                    case WM_RBUTTONUP:
                        if (MouseUpEvent != null)
                        {
                            MouseUpEvent(this, GetMousePoint(lParam), MouseButtons.Right);
                        }
                        break;
                    }
                }
            }

            return(WinUserDll.CallNextHookEx(hookId, nCode, wParam, lParam));
        }
示例#2
0
        private int KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (wParam == (IntPtr)WM_KEYDOWN)
                {
                    if (KeyboardDownEvent != null)
                    {
                        KeyboardDownEvent(this, (Keys)Marshal.ReadInt32(lParam));
                    }
                }
                else if (wParam == (IntPtr)WM_KEYUP)
                {
                    if (KeyboardUpEvent != null)
                    {
                        KeyboardUpEvent(this, (Keys)Marshal.ReadInt32(lParam));
                    }
                }
            }

            return(WinUserDll.CallNextHookEx(hookId, nCode, wParam, lParam));
        }