Пример #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));
        }
Пример #3
0
 public void UnHook()
 {
     WinUserDll.UnhookWindowsHookEx(hookId);
 }
Пример #4
0
 public void SetHook()
 {
     hookProc = new WinUserDll.HookProc(MouseHookProc);
     hookId   = WinUserDll.SetWindowsHookEx(WH_MOUSE_LL, hookProc, IntPtr.Zero, 0);
 }
Пример #5
0
 public void SetHook()
 {
     hookProc = new WinUserDll.HookProc(KeyboardHookProc);
     hookId   = WinUserDll.SetWindowsHookEx(WH_KEYBOARD_LL, hookProc, IntPtr.Zero, 0);
 }