Esempio n. 1
0
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                MouseLlHookStruct mouseHookStruct = (MouseLlHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLlHookStruct));

                MouseButtons button     = MouseButtons.None;
                var          mouseDelta = 0;
                var          clickCount = 0;
                var          mouseDown  = false;
                var          mouseUp    = false;

                switch (wParam)
                {
                case WM_LBUTTONDOWN:
                    mouseDown  = true;
                    button     = MouseButtons.Left;
                    clickCount = 1;
                    break;
                    //case WM_LBUTTONUP:
                    //    mouseUp = true;
                    //    button = MouseButtons.Left;
                    //    clickCount = 1;
                    //    break;
                    //case WM_LBUTTONDBLCLK:
                    //    button = MouseButtons.XButton1;
                    //    clickCount = 2;
                    //    break;
                    //case WM_RBUTTONDOWN:
                    //    mouseDown = true;
                    //    button = MouseButtons.Right;
                    //    clickCount = 1;
                    //    break;
                    //case WM_RBUTTONUP:
                    //    mouseUp = true;
                    //    button = MouseButtons.Right;
                    //    clickCount = 1;
                    //    break;
                    //case WM_RBUTTONDBLCLK:
                    //    button = MouseButtons.Right;
                    //    clickCount = 2;
                    //    break;
                    //case WM_MOUSEWHEEL:
                    //    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                    //    break;
                }


                var e = new MouseEventExtArgs(button, clickCount, mouseHookStruct.Point.X, mouseHookStruct.Point.Y, mouseDelta);

                if (e.Button == MouseButtons.Left)
                {
                    var point = new System.Drawing.Point();
                    point.X = mouseHookStruct.Point.X;
                    point.Y = mouseHookStruct.Point.Y;
                    PositionClick.Add(point);
                }



                if (SMouseUp != null && mouseUp)
                {
                    SMouseUp.Invoke(null, e);
                }


                if (SMouseDown != null && mouseDown)
                {
                    SMouseDown.Invoke(null, e);
                }


                if (SMouseClick != null && clickCount > 0)
                {
                    SMouseClick.Invoke(null, e);
                }


                if (SMouseClickExt != null && clickCount > 0)
                {
                    SMouseClickExt.Invoke(null, e);
                }


                if (SMouseDoubleClick != null && clickCount == 2)
                {
                    SMouseDoubleClick.Invoke(null, e);
                }

                if (SMouseWheel != null && mouseDelta != 0)
                {
                    SMouseWheel.Invoke(null, e);
                }

                if ((SMouseMove != null || SMouseMoveExt != null) && (_mOldX != mouseHookStruct.Point.X || _mOldY != mouseHookStruct.Point.Y))
                {
                    _mOldX = mouseHookStruct.Point.X;
                    _mOldY = mouseHookStruct.Point.Y;
                    SMouseMove?.Invoke(null, e);

                    SMouseMoveExt?.Invoke(null, e);
                }

                if (e.Handled)
                {
                    return(-1);
                }
            }


            return(CallNextHookEx(_sMouseHookHandle, nCode, wParam, lParam));
        }
 private void HookManager_MouseClickExt(object sender, MouseEventExtArgs e)
 {
     MMouseClickExt?.Invoke(this, e);
 }