コード例 #1
0
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                switch ((MouseMessage)wParam)
                {
                case MouseMessage.WM_LBUTTONDOWN:
                    OnLeftButtonDown?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Left,
                        State  = MouseState.MouseDown
                    });
                    break;

                case MouseMessage.WM_LBUTTONUP:
                    OnLeftButtonUp?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Left,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_LBUTTONDBLCLK:
                    OnLeftDoubleClick?.Invoke(null, new MouseEventsArgs
                    {
                        Button      = MouseButtons.Left,
                        State       = MouseState.MouseUp,
                        DoubleClick = true
                    });
                    break;

                case MouseMessage.WM_RBUTTONDOWN:
                    OnRightButtonDown?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Right,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_RBUTTONUP:
                    OnRightButtonUp?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Right,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_MOUSEMOVE:
                    OnMouseMove?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.None,
                        State  = MouseState.MouseMove
                    });
                    break;
                }
            }
            return(NativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam));
        }
コード例 #2
0
 private static void OnOverrideLeftButtonDown(int x, int y)
 {
     _updateLeftDown = true;
     OnLeftButtonDown?.Invoke(x, y);
 }
コード例 #3
0
        private void HandleMouseEvent(MouseEvent mouseEvent)
        {
            int x = mouseEvent.X;
            int y = mouseEvent.Y;

            switch (mouseEvent.HardwareEvent)
            {
            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOWN:
            {
                _updateLeftDown = true;
                HitScenes(x, y);
                OnLeftButtonDown?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONUP:
            {
                _updateLeftUp = true;
                HitScenes(x, y);
                OnLeftButtonUp?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOWN:
            {
                _updateRightDown = true;
                HitScenes(x, y);
                OnRightButtonDown?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP:
            {
                _updateRightUp = true;
                HitScenes(x, y);
                OnRightButtonUp?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MOVE:
            {
                // OnMove will be called from the Update method.
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOUBLECLICK:
            {
                OnLeftButtonDoubleClicked?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOUBLECLICK:
            {
                OnRightButtonDoubleClicked?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONDOWN:
            {
                _updateMiddleDown = true;
                HitScenes(x, y);
                OnMiddleButtonDown?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONUP:
            {
                _updateMiddleUp = true;
                HitScenes(x, y);
                OnMiddleButtonUp?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONDOUBLECLICK:
            {
                OnMiddleButtonDoubleClicked?.Invoke(x, y);
                break;
            }

            case EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_WHEEL:
            {
                OnMouseWheelChanged?.Invoke(mouseEvent.WheelDelta);
                break;
            }

            default:
                throw new System.NotImplementedException();
            }
        }
コード例 #4
0
        public static void InvokeEvents()
        {
            if (OnLeftButtonDown != null && IsButtonDown(MouseButton.Left))
            {
                OnLeftButtonDown.Invoke(currentState);
            }
            if (OnLeftButtonPressed != null && IsButtonPressed(MouseButton.Left))
            {
                OnLeftButtonPressed.Invoke(currentState);
            }
            if (OnLeftButtonReleased != null && IsButtonReleased(MouseButton.Left))
            {
                OnLeftButtonReleased.Invoke(currentState);
            }

            if (OnRightButtonDown != null && IsButtonDown(MouseButton.Right))
            {
                OnRightButtonDown.Invoke(currentState);
            }
            if (OnRightButtonPressed != null && IsButtonPressed(MouseButton.Right))
            {
                OnRightButtonPressed.Invoke(currentState);
            }
            if (OnRightButtonReleased != null && IsButtonReleased(MouseButton.Right))
            {
                OnRightButtonReleased.Invoke(currentState);
            }

            if (OnMiddleButtonDown != null && IsButtonDown(MouseButton.Middle))
            {
                OnMiddleButtonDown.Invoke(currentState);
            }
            if (OnMiddleButtonPressed != null && IsButtonPressed(MouseButton.Middle))
            {
                OnMiddleButtonPressed.Invoke(currentState);
            }
            if (OnMiddleButtonReleased != null && IsButtonReleased(MouseButton.Middle))
            {
                OnMiddleButtonReleased.Invoke(currentState);
            }

            if (OnXButton1Down != null && IsButtonDown(MouseButton.XButton1))
            {
                OnXButton1Down.Invoke(currentState);
            }
            if (OnXButton1Pressed != null && IsButtonPressed(MouseButton.XButton1))
            {
                OnXButton1Pressed.Invoke(currentState);
            }
            if (OnXButton1Released != null && IsButtonReleased(MouseButton.XButton1))
            {
                OnXButton1Released.Invoke(currentState);
            }

            if (OnXButton2Down != null && IsButtonDown(MouseButton.XButton2))
            {
                OnXButton2Down.Invoke(currentState);
            }
            if (OnXButton2Pressed != null && IsButtonPressed(MouseButton.XButton2))
            {
                OnXButton2Pressed.Invoke(currentState);
            }
            if (OnXButton2Released != null && IsButtonReleased(MouseButton.XButton2))
            {
                OnXButton2Released.Invoke(currentState);
            }

            if (OnButtonDown != null && IsButtonDown(MouseButton.Any))
            {
                OnButtonDown.Invoke(currentState, GetDownButtons());
            }
            if (OnButtonPressed != null && IsButtonPressed(MouseButton.Any))
            {
                OnButtonPressed.Invoke(currentState, GetPressedButtons());
            }
            if (OnButtonReleased != null && IsButtonReleased(MouseButton.Any))
            {
                OnButtonReleased.Invoke(currentState, GetReleasedButtons());
            }

            if (OnMouseWheelUp != null && IsMouseWheelUp())
            {
                OnMouseWheelUp.Invoke(currentState);
            }
            if (OnMouseWheelDown != null && IsMouseWheelDown())
            {
                OnMouseWheelDown.Invoke(currentState);
            }

            if (OnMouseMove != null && IsMouseMoving())
            {
                OnMouseMove.Invoke(currentState, GetMoveDirection());
            }
        }