public void UnHook()
 {
     Win32Api.UnhookWindowsHookEx(hHook);
 }
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
            if (nCode < 0)
            {
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
            else
            {
                if (MouseClickEvent != null)
                {
                    MouseButtons button     = MouseButtons.None;
                    int          clickCount = 0;
                    switch ((Int32)wParam)
                    {
                    case WM_LBUTTONDOWN:
                        button     = MouseButtons.Left;
                        clickCount = 1;
                        MouseDownEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_LBUTTONDBLCLK:
                        button     = MouseButtons.Left;
                        clickCount = 2;
                        MouseDownEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_RBUTTONDOWN:
                        button     = MouseButtons.Right;
                        clickCount = 1;
                        MouseDownEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_MBUTTONDOWN:
                        button     = MouseButtons.Middle;
                        clickCount = 1;
                        MouseDownEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_LBUTTONUP:
                        button     = MouseButtons.Left;
                        clickCount = 1;
                        MouseUpEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_RBUTTONUP:
                        button     = MouseButtons.Right;
                        clickCount = 1;
                        MouseUpEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;

                    case WM_MBUTTONUP:
                        button     = MouseButtons.Middle;
                        clickCount = 1;
                        MouseUpEvent(this, new MouseEventArgs(button, clickCount, point.X, point.Y, 0));
                        break;
                    }

                    var e = new MouseEventArgs(button, clickCount, point.X, point.Y, 0);
                    MouseClickEvent(this, e);
                }
                this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y);
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
        }
 public int SetHook()
 {
     hProc = new Win32Api.HookProc(MouseHookProc);
     hHook = Win32Api.SetWindowsHookEx(WH_MOUSE_LL, hProc, IntPtr.Zero, 0);
     return(hHook);
 }