Beispiel #1
0
        private static int HookProcedureCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (wParam.ToInt32() == (int)Native.Message.WM_LBUTTONDBLCLK &&
                    !IsReEnteredCallback())
                {
                    IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
                    FindSlideViewWindowHandle(handle);
                    if (IsMouseWithinSlideViewWindow() &&
                        DoubleClick != null)
                    {
                        DoubleClick(selectedRange);
                    }
                }

                // Left mouse button up/released
                if (wParam.ToInt32() == (uint)Native.Message.WM_LBUTTONUP)
                {
                    LeftButtonUp?.Invoke();
                }

                // Right mouse button down
                if (wParam.ToInt32() == (uint)Native.Message.WM_RBUTTONDOWN)
                {
                    RightClickCoordinates = new Coordinates(Cursor.Position.X, Cursor.Position.Y);
                }

                UpdateStartTime();
            }
            return(Native.CallNextHookEx(0, nCode, wParam, lParam));
        }
Beispiel #2
0
        private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // Parse system messages
            if (nCode >= 0)
            {
                if (MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
                {
                    LeftButtonDown?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_LBUTTONUP == (MouseMessages)wParam)
                {
                    LeftButtonUp?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_RBUTTONDOWN == (MouseMessages)wParam)
                {
                    RightButtonDown?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_RBUTTONUP == (MouseMessages)wParam)
                {
                    RightButtonUp?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_MOUSEMOVE == (MouseMessages)wParam)
                {
                    MouseMove?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_MOUSEWHEEL == (MouseMessages)wParam)
                {
                    MouseWheel?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_LBUTTONDBLCLK == (MouseMessages)wParam)
                {
                    DoubleClick?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_MBUTTONDOWN == (MouseMessages)wParam)
                {
                    MiddleButtonDown?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
                if (MouseMessages.WM_MBUTTONUP == (MouseMessages)wParam)
                {
                    MiddleButtonUp?.Invoke(
                        (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
                }
            }

            return(CallNextHookEx(_hookId, nCode, wParam, lParam));
        }
Beispiel #3
0
        public void Update()
        {
            var mouseState = _mouse.GetState();

            if (mouseState.LeftButton != _previousMouseState.LeftButton)
            {
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    LeftButtonDown?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
                else
                {
                    LeftButtonUp?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
            }

            if (mouseState.MiddleButton != _previousMouseState.MiddleButton)
            {
                if (mouseState.MiddleButton == ButtonState.Pressed)
                {
                    MiddleButtonDown?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
                else
                {
                    MiddleButtonUp?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
            }

            if (mouseState.RightButton != _previousMouseState.RightButton)
            {
                if (mouseState.RightButton == ButtonState.Pressed)
                {
                    RightButtonDown?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
                else
                {
                    RightButtonUp?.Invoke(this, new MouseEventArgs(ref mouseState));
                }
            }

            if (mouseState.Position != _previousMouseState.Position)
            {
                MouseMove?.Invoke(this, new MouseMoveEventArgs(mouseState, _previousMouseState.Position));
            }

            if (mouseState.ScrollWheelValue != _previousMouseState.ScrollWheelValue)
            {
                MouseWheel?.Invoke(this, new MouseWheelEventArgs(mouseState, mouseState.ScrollWheelValue - _previousMouseState.ScrollWheelValue));
            }

            _previousMouseState = mouseState;
        }
        public static void Update()
        {
            MouseState mState = Mouse.GetState();

            if (mState.LeftButton == ButtonState.Pressed)
            {
                if (mouseReleased == true)
                {
                    // Left button down!
                    mouseReleased     = false;
                    downClickPosition = new Vector2(mState.Position.X, mState.Position.Y);
                    LeftButtonDown?.Invoke(
                        null,
                        new MouseClickEventArgs(new Vector2(mState.Position.X, mState.Position.Y))
                        );
                }
                // Swipe on the screen.
                else
                {
                    // Left button down and swipe!
                    if (downClickPosition.X > 0)
                    {
                        var distance = Vector2.Distance(downClickPosition, new Vector2(mState.Position.X, mState.Position.Y));
                        if (distance > distanceForDetectedSwipe)
                        {
                            Direction direction = GetSwipeDirection(downClickPosition, new Vector2(mState.Position.X, mState.Position.Y));
                            LeftButtonSwipe?.Invoke(
                                null,
                                new MouseSwipeEventArgs(
                                    downClickPosition,
                                    new Vector2(mState.Position.X, mState.Position.Y),
                                    direction
                                    )
                            {
                            }
                                );
                        }
                    }
                }
            }
            else if (mState.LeftButton == ButtonState.Released && mouseReleased == false)
            {
                // Left button up!
                mouseReleased     = true;
                downClickPosition = new Vector2(-1, -1);
                LeftButtonUp?.Invoke(
                    null,
                    new MouseClickEventArgs(new Vector2(mState.Position.X, mState.Position.Y))
                    );
            }
        }
        /// <summary>
        ///     Callback function
        /// </summary>
        private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // parse system messages
            if (nCode < 0)
            {
                return(NativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam));
            }
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch ((MouseFlags)wParam)
            {
            case MouseFlags.LeftDown:
                LeftButtonDown?.Invoke((MouseInput)Marshal.PtrToStructure(lParam, typeof(MouseInput)));
                break;

            case MouseFlags.LeftUp:
                LeftButtonUp?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.RightDown:
                RightButtonDown?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.RightUp:
                RightButtonUp?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.Move:
                MouseMove?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.Wheel:
                MouseWheel?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.DoubleLeftClick:
                DoubleClick?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.MiddleDown:
                MiddleButtonDown?.Invoke(MouseInputToStructure(lParam));
                break;

            case MouseFlags.MiddleUp:
                MiddleButtonUp?.Invoke(MouseInputToStructure(lParam));
                break;
            }

            return(NativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam));
        }
        /// <summary>
        /// Callback function
        /// </summary>
        protected override IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // parse system messages
            if (nCode >= 0)
            {
                switch ((WM_MESSAGE)wParam)
                {
                case WM_MESSAGE.WM_LBUTTONDOWN:
                    LeftButtonDown?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_LBUTTONUP:
                    LeftButtonUp?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_RBUTTONDOWN:
                    RightButtonDown?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_RBUTTONUP:
                    RightButtonUp?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_MOUSEMOVE:
                    MouseMove?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_MOUSEWHEEL:
                    MouseWheel?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_LBUTTONDBLCLK:
                    DoubleClick?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_MBUTTONDOWN:
                    MiddleButtonDown?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;

                case WM_MESSAGE.WM_MBUTTONUP:
                    MiddleButtonUp?.Invoke((MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)));
                    break;
                }
            }
            return(CallNextHookEx(hookID, nCode, wParam, lParam));
        }
Beispiel #7
0
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Delta       = BitConverter.ToInt16(e.Bytes, 20),
            };

            Debug.WriteLine($"Mouse Message Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Delta: {eventArgs.Delta}");

            if (eventArgs.MessageCode == LeftButtonUpMessageCode)
            {
                LeftButtonUp?.Invoke(this, eventArgs);
            }

            MessageReceived?.Invoke(this, eventArgs);
        }
Beispiel #8
0
        internal static void OnWndProc(WndEventArgs args)
        {
            if (OnMessage != null)
            {
                WindowMessage eventHandle = null;
                switch (args.Msg)
                {
                case (uint)WindowMessages.KeyDown:
                    NotifyEventHandlers(eventHandle = new KeyDown(args));
                    break;

                case (uint)WindowMessages.KeyUp:
                    NotifyEventHandlers(eventHandle = new KeyUp(args));
                    break;

                case (uint)WindowMessages.LeftButtonDoubleClick:
                    NotifyEventHandlers(eventHandle = new LeftButtonDoubleClick(args));
                    break;

                case (uint)WindowMessages.LeftButtonDown:
                    NotifyEventHandlers(eventHandle = new LeftButtonDown(args));
                    break;

                case (uint)WindowMessages.LeftButtonUp:
                    NotifyEventHandlers(eventHandle = new LeftButtonUp(args));
                    break;

                case (uint)WindowMessages.MiddleButtonDoubleClick:
                    NotifyEventHandlers(eventHandle = new MiddleButtonDoubleClick(args));
                    break;

                case (uint)WindowMessages.MiddleButtonDown:
                    NotifyEventHandlers(eventHandle = new MiddleButtonDown(args));
                    break;

                case (uint)WindowMessages.MiddleButtonUp:
                    NotifyEventHandlers(eventHandle = new MiddleButtonUp(args));
                    break;

                case (uint)WindowMessages.MouseMove:
                    NotifyEventHandlers(eventHandle = new MouseMove(args));
                    break;

                case (uint)WindowMessages.MouseWheel:
                    NotifyEventHandlers(eventHandle = new MouseWheel(args));
                    break;

                case (uint)WindowMessages.RightButtonDoubleClick:
                    NotifyEventHandlers(eventHandle = new RightButtonDoubleClick(args));
                    break;

                case (uint)WindowMessages.RightButtonDown:
                    NotifyEventHandlers(eventHandle = new RightButtonDown(args));
                    break;

                case (uint)WindowMessages.RightButtonUp:
                    NotifyEventHandlers(eventHandle = new RightButtonUp(args));
                    break;
                }

                if (eventHandle != null)
                {
                    // Trigger the event
                    OnMessage(eventHandle);
                    args.Process = eventHandle.Process;

                    // Update previous mouse position
                    if (eventHandle is MouseEvent)
                    {
                        _previousMousePosition = Game.CursorPos2D;
                    }
                }
            }
        }
Beispiel #9
0
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Delta       = BitConverter.ToInt16(e.Bytes, 20),
            };

            Debug.WriteLine($"Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Delta: {eventArgs.Delta}");

            MessageReceived?.Invoke(this, eventArgs);

            switch (GetMessageCode(eventArgs.MessageCode))
            {
            case MouseMessageCode.MouseMove:
                MouseMove?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDown:
                LeftButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonUp:
                LeftButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDblClk:
                LeftButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDown:
                RightButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonUp:
                RightButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDblClk:
                RightButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDown:
                MiddleButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonUp:
                MiddleButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDblClk:
                MiddleButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseWheel:
                MouseWheel?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDown:
                XButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonUp:
                XButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDblClk:
                XButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseHWheel:
                MouseHWheel?.Invoke(this, eventArgs);
                break;

            default:
                break;
            }

            if (_messageHandlers.ContainsKey(eventArgs.MessageCode))
            {
                _messageHandlers[eventArgs.MessageCode]?.Invoke(this, eventArgs);
            }
        }
Beispiel #10
0
 public static void StopAllActions()
 {
     LeftButtonUp?.Invoke();
 }
Beispiel #11
0
        /// <summary>
        /// Callback function
        /// </summary>
        private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // parse system messages
            if (nCode >= 0)
            {
                var data    = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                var message = (MouseMessages)wParam;

                var isDown = false;
                var isUp   = false;
                SimpleMouseButtons button;


                switch (message)
                {
                case MouseMessages.WM_MOUSEMOVE:
                    break;

                case MouseMessages.WM_LBUTTONDOWN:
                    isDown = true;
                    break;

                case MouseMessages.WM_RBUTTONDOWN:
                    isDown = true;
                    break;

                case MouseMessages.WM_MBUTTONDOWN:
                    isDown = true;
                    break;

                case MouseMessages.WM_LBUTTONUP:
                    isUp = true;
                    break;

                case MouseMessages.WM_RBUTTONUP:
                    isUp = true;
                    break;

                case MouseMessages.WM_MBUTTONUP:
                    isUp = true;
                    break;

                case MouseMessages.WM_MOUSEWHEEL:
                    break;

                case MouseMessages.WM_MOUSEHWHEEL:
                    break;

                case MouseMessages.WM_LBUTTONDBLCLK:
                    break;

                case MouseMessages.WM_RBUTTONDBLCLK:
                    break;

                case MouseMessages.WM_MBUTTONDBLCLK:
                    break;

                case MouseMessages.WM_XBUTTONDOWN:
                    isDown = true;
                    break;

                case MouseMessages.WM_XBUTTONUP:
                    isUp = true;
                    break;

                case MouseMessages.WM_XBUTTONDBLCLK:
                    break;

                default:
                    break;
                }


                if (MouseMessages.WM_LBUTTONDOWN == message)
                {
                    LeftButtonDown?.Invoke(data);
                }
                if (MouseMessages.WM_LBUTTONUP == message)
                {
                    LeftButtonUp?.Invoke(data);
                }
                if (MouseMessages.WM_RBUTTONDOWN == message)
                {
                    RightButtonDown?.Invoke(data);
                }
                if (MouseMessages.WM_RBUTTONUP == message)
                {
                    RightButtonUp?.Invoke(data);
                }
                if (MouseMessages.WM_MOUSEMOVE == message)
                {
                    MouseMove?.Invoke(data);
                }
                if (MouseMessages.WM_MOUSEWHEEL == message)
                {
                    MouseWheel?.Invoke(data);
                }
                if (MouseMessages.WM_LBUTTONDBLCLK == message)
                {
                    DoubleClick?.Invoke(data);
                }
                if (MouseMessages.WM_MBUTTONDOWN == message)
                {
                    MiddleButtonDown?.Invoke(data);
                }
                if (MouseMessages.WM_MBUTTONUP == message)
                {
                    MiddleButtonUp?.Invoke(data);
                }

                //Generic Event, fire with type
                MouseEvent?.Invoke(data, message);
            }
            return(CallNextHookEx(hookID, nCode, wParam, lParam));
        }
Beispiel #12
0
 private void OnLeftButtonUp(MouseHookEventArgs e)
 {
     LeftButtonUp?.Invoke(this, e);
     OnMouseEvent(e);
 }
Beispiel #13
0
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var modifiers = BitConverter.ToUInt16(e.Bytes, 24);
            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Modifiers   = modifiers,
                Shift       = (modifiers & 0b100) > 0,
                Control     = (modifiers & 0b10) > 0,
                Alt         = (modifiers & 0b1) > 0,
            };

            var messageCode = GetMessageCode(eventArgs.MessageCode);

            if (messageCode == MouseMessageCode.MouseWheel)
            {
                eventArgs.Delta = BitConverter.ToInt16(e.Bytes, 20);
            }
            else if (messageCode == MouseMessageCode.NCXButtonDown ||
                     messageCode == MouseMessageCode.NCXButtonUp ||
                     messageCode == MouseMessageCode.NCXButtonDblClk ||
                     messageCode == MouseMessageCode.XButtonDown ||
                     messageCode == MouseMessageCode.XButtonUp ||
                     messageCode == MouseMessageCode.XButtonDblClk)
            {
                eventArgs.XButtons = BitConverter.ToInt16(e.Bytes, 20);
            }

            Debug.Write($"Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Modifiers: {eventArgs.Modifiers:x}; ");
            Debug.WriteLine($"Delta: {eventArgs.Delta}; XButtons: {eventArgs.XButtons}");

            MessageReceived?.Invoke(this, eventArgs);

            switch (messageCode)
            {
            case MouseMessageCode.MouseMove:
                MouseMove?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDown:
                LeftButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonUp:
                LeftButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDblClk:
                LeftButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDown:
                RightButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonUp:
                RightButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDblClk:
                RightButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDown:
                MiddleButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonUp:
                MiddleButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDblClk:
                MiddleButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseWheel:
                MouseWheel?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDown:
                XButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonUp:
                XButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDblClk:
                XButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseHWheel:
                MouseHWheel?.Invoke(this, eventArgs);
                break;

            default:
                break;
            }

            if (_messageHandlers.ContainsKey(eventArgs.MessageCode))
            {
                _messageHandlers[eventArgs.MessageCode]?.Invoke(this, eventArgs);
            }
        }