Esempio n. 1
0
        static MouseFlags SetControlKeyStates(WindowsConsole.MouseEventRecord mouseEvent, MouseFlags mouseFlag)
        {
            if (mouseEvent.ControlKeyState.HasFlag(WindowsConsole.ControlKeyState.RightControlPressed) ||
                mouseEvent.ControlKeyState.HasFlag(WindowsConsole.ControlKeyState.LeftControlPressed))
            {
                mouseFlag |= MouseFlags.ButtonCtrl;
            }

            if (mouseEvent.ControlKeyState.HasFlag(WindowsConsole.ControlKeyState.ShiftPressed))
            {
                mouseFlag |= MouseFlags.ButtonShift;
            }

            if (mouseEvent.ControlKeyState.HasFlag(WindowsConsole.ControlKeyState.RightAltPressed) ||
                mouseEvent.ControlKeyState.HasFlag(WindowsConsole.ControlKeyState.LeftAltPressed))
            {
                mouseFlag |= MouseFlags.ButtonAlt;
            }
            return(mouseFlag);
        }
Esempio n. 2
0
        async Task ProcessContinuousButtonPressedAsync(WindowsConsole.MouseEventRecord mouseEvent, MouseFlags mouseFlag)
        {
            while (IsButtonPressed)
            {
                await Task.Delay(200);

                var me = new MouseEvent()
                {
                    X     = mouseEvent.MousePosition.X,
                    Y     = mouseEvent.MousePosition.Y,
                    Flags = mouseFlag
                };

                var view = Application.wantContinuousButtonPressedView;
                if (view == null)
                {
                    break;
                }
                if (IsButtonPressed && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
                {
                    mouseHandler(me);
                }
            }
        }
Esempio n. 3
0
        MouseEvent ToDriverMouse(WindowsConsole.MouseEventRecord mouseEvent)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            if (IsButtonDoubleClicked)
            {
                Task.Run(async() => {
                    await Task.Delay(100);
                    IsButtonDoubleClicked = false;
                });
            }

            // The ButtonState member of the MouseEvent structure has bit corresponding to each mouse button.
            // This will tell when a mouse button is pressed. When the button is released this event will
            // be fired with it's bit set to 0. So when the button is up ButtonState will be 0.
            // To map to the correct driver events we save the last pressed mouse button so we can
            // map to the correct clicked event.
            if ((LastMouseButtonPressed != null || IsButtonReleased) && mouseEvent.ButtonState != 0)
            {
                LastMouseButtonPressed = null;
                IsButtonPressed        = false;
                IsButtonReleased       = false;
            }

            if ((mouseEvent.EventFlags == 0 && LastMouseButtonPressed == null && !IsButtonDoubleClicked) ||
                (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved &&
                 mouseEvent.ButtonState != 0 && !IsButtonReleased && !IsButtonDoubleClicked))
            {
                switch (mouseEvent.ButtonState)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1Pressed;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2Pressed;
                    break;

                case WindowsConsole.ButtonState.RightmostButtonPressed:
                    mouseFlag = MouseFlags.Button4Pressed;
                    break;
                }

                if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved)
                {
                    mouseFlag       |= MouseFlags.ReportMousePosition;
                    point            = new Point();
                    IsButtonReleased = false;
                }
                else
                {
                    point = new Point()
                    {
                        X = mouseEvent.MousePosition.X,
                        Y = mouseEvent.MousePosition.Y
                    };
                }
                LastMouseButtonPressed = mouseEvent.ButtonState;
                IsButtonPressed        = true;

                if ((mouseFlag & MouseFlags.ReportMousePosition) == 0)
                {
                    Task.Run(async() => {
                        while (IsButtonPressed)
                        {
                            await Task.Delay(200);
                            var me = new MouseEvent()
                            {
                                X     = mouseEvent.MousePosition.X,
                                Y     = mouseEvent.MousePosition.Y,
                                Flags = mouseFlag
                            };

                            if (IsButtonPressed && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
                            {
                                mouseHandler(me);
                                mainLoop.Driver.Wakeup();
                            }
                        }
                    });
                }
            }
            else if ((mouseEvent.EventFlags == 0 || mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved) &&
                     LastMouseButtonPressed != null && !IsButtonReleased && !IsButtonDoubleClicked)
            {
                switch (LastMouseButtonPressed)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1Released;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2Released;
                    break;

                case WindowsConsole.ButtonState.RightmostButtonPressed:
                    mouseFlag = MouseFlags.Button4Released;
                    break;
                }
                IsButtonPressed  = false;
                IsButtonReleased = true;
            }
            else if ((mouseEvent.EventFlags == 0 || mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved) &&
                     IsButtonReleased)
            {
                var p = new Point()
                {
                    X = mouseEvent.MousePosition.X,
                    Y = mouseEvent.MousePosition.Y
                };
                if (p == point)
                {
                    switch (LastMouseButtonPressed)
                    {
                    case WindowsConsole.ButtonState.Button1Pressed:
                        mouseFlag = MouseFlags.Button1Clicked;
                        break;

                    case WindowsConsole.ButtonState.Button2Pressed:
                        mouseFlag = MouseFlags.Button2Clicked;
                        break;

                    case WindowsConsole.ButtonState.RightmostButtonPressed:
                        mouseFlag = MouseFlags.Button4Clicked;
                        break;
                    }
                }
                else
                {
                    mouseFlag = 0;
                }
                LastMouseButtonPressed = null;
                IsButtonReleased       = false;
            }
            else if (mouseEvent.EventFlags.HasFlag(WindowsConsole.EventFlags.DoubleClick))
            {
                switch (mouseEvent.ButtonState)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1DoubleClicked;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2DoubleClicked;
                    break;

                case WindowsConsole.ButtonState.RightmostButtonPressed:
                    mouseFlag = MouseFlags.Button4DoubleClicked;
                    break;
                }
                IsButtonDoubleClicked = true;
            }
            else if (mouseEvent.EventFlags == 0 && mouseEvent.ButtonState != 0 && IsButtonDoubleClicked)
            {
                switch (mouseEvent.ButtonState)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1TripleClicked;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2TripleClicked;
                    break;

                case WindowsConsole.ButtonState.RightmostButtonPressed:
                    mouseFlag = MouseFlags.Button4TripleClicked;
                    break;
                }
                IsButtonDoubleClicked = false;
            }
            else if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseWheeled)
            {
                switch (mouseEvent.ButtonState)
                {
                case WindowsConsole.ButtonState.WheeledUp:
                    mouseFlag = MouseFlags.WheeledUp;
                    break;

                case WindowsConsole.ButtonState.WheeledDown:
                    mouseFlag = MouseFlags.WheeledDown;
                    break;
                }
            }
            else if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved)
            {
                mouseFlag = MouseFlags.ReportMousePosition;
            }

            mouseFlag = SetControlKeyStates(mouseEvent, mouseFlag);

            return(new MouseEvent()
            {
                X = mouseEvent.MousePosition.X,
                Y = mouseEvent.MousePosition.Y,
                Flags = mouseFlag
            });
        }
Esempio n. 4
0
        private MouseEvent ToDriverMouse(WindowsConsole.MouseEventRecord mouseEvent)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            // The ButtonState member of the MouseEvent structure has bit corresponding to each mouse button.
            // This will tell when a mouse button is pressed. When the button is released this event will
            // be fired with it's bit set to 0. So when the button is up ButtonState will be 0.
            // To map to the correct driver events we save the last pressed mouse button so we can
            // map to the correct clicked event.
            if (LastMouseButtonPressed != null && mouseEvent.ButtonState != 0)
            {
                LastMouseButtonPressed = null;
            }

            if (mouseEvent.EventFlags == 0 && LastMouseButtonPressed == null)
            {
                switch (mouseEvent.ButtonState)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1Pressed;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2Pressed;
                    break;

                case WindowsConsole.ButtonState.Button3Pressed:
                    mouseFlag = MouseFlags.Button3Pressed;
                    break;
                }
                LastMouseButtonPressed = mouseEvent.ButtonState;
            }
            else if (mouseEvent.EventFlags == 0 && LastMouseButtonPressed != null)
            {
                switch (LastMouseButtonPressed)
                {
                case WindowsConsole.ButtonState.Button1Pressed:
                    mouseFlag = MouseFlags.Button1Clicked;
                    break;

                case WindowsConsole.ButtonState.Button2Pressed:
                    mouseFlag = MouseFlags.Button2Clicked;
                    break;

                case WindowsConsole.ButtonState.Button3Pressed:
                    mouseFlag = MouseFlags.Button3Clicked;
                    break;
                }
                LastMouseButtonPressed = null;
            }
            else if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved)
            {
                mouseFlag = MouseFlags.ReportMousePosition;
            }

            return(new MouseEvent()
            {
                X = mouseEvent.MousePosition.X,
                Y = mouseEvent.MousePosition.Y,
                Flags = mouseFlag
            });
        }