Example #1
0
 private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
 {
     if (nCode >= 0 && this.OnMouseActivity != null)
     {
         MouseButtons button = MouseButtons.None;
         if (wParam != 513)
         {
             if (wParam == 516)
             {
                 button = MouseButtons.Right;
             }
         }
         else
         {
             button = MouseButtons.Left;
         }
         int clickCount = 0;
         if (button != MouseButtons.None)
         {
             if (wParam == 515 || wParam == 518)
             {
                 clickCount = 2;
             }
             else
             {
                 clickCount = 1;
             }
         }
         MouseHookStruct MyMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
         MouseEventArgs  e = new MouseEventArgs(button, clickCount, MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y, 0);
         this.OnMouseActivity(this, e);
     }
     return(GlobalHook.CallNextHookEx(GlobalHook._hMouseHook, nCode, wParam, lParam));
 }
Example #2
0
        private int MouseHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            if ((nCode >= 0) && (OnMouseActivity != null))
            {
                MouseButtons button = MouseButtons.None;
                switch (wParam)
                {
                case WM_LBUTTONDOWN:        //左键按下
                    //case WM_LBUTTONUP:    //右键按下
                    //case WM_LBUTTONDBLCLK:   //同时按下
                    button = MouseButtons.Left;
                    break;

                case WM_RBUTTONDOWN:
                    //case WM_RBUTTONUP:
                    //case WM_RBUTTONDBLCLK:
                    button = MouseButtons.Right;
                    break;
                }
                int clickCount = 0;
                if (button != MouseButtons.None)
                {
                    if (wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK)
                    {
                        clickCount = 2;
                    }
                    else
                    {
                        clickCount = 1;
                    }
                }

                //Marshall the data from callback.
                MouseHookStruct MyMouseHookStruct =
                    (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
                MouseEventArgs e = new MouseEventArgs(
                    button,
                    clickCount,
                    MyMouseHookStruct.pt.x,
                    MyMouseHookStruct.pt.y,
                    0);
                OnMouseActivity(this, e);
            }
            return(CallNextHookEx(_hMouseHook, nCode, wParam, lParam));
        }