コード例 #1
0
 MouseEvent ProcessButtonState(Curses.MouseEvent cev, MouseFlags mf)
 {
     return(new MouseEvent()
     {
         X = cev.X,
         Y = cev.Y,
         Flags = mf
     });
 }
コード例 #2
0
 public MOUSEINPUT(Point point, MouseFlags flags, bool absolute)
 {
     dx          = (int)point.X;
     dy          = (int)point.Y;
     dwFlags     = (uint)(flags | (absolute ? MouseFlags.Absolute : 0));
     time        = 0;
     mouseData   = 0;
     dwExtraInfo = IntPtr.Zero;
 }
コード例 #3
0
ファイル: ContextMenuTests.cs プロジェクト: BDisp/gui.cs
        public void MouseFlagsChanged_Event()
        {
            var oldMouseFlags = new MouseFlags();
            var cm            = new ContextMenu();

            cm.MouseFlagsChanged += (e) => oldMouseFlags = e;

            cm.MouseFlags = MouseFlags.Button2Clicked;
            Assert.Equal(MouseFlags.Button2Clicked, cm.MouseFlags);
            Assert.Equal(MouseFlags.Button3Clicked, oldMouseFlags);
        }
コード例 #4
0
        public bool moveMouseToPoint(POINT target, bool absolute = true)
        {
            MouseFlags flag       = absolute ? MouseFlags.MOUSE_MOVE_ABSOLUTE : MouseFlags.MOUSEEVENTF_MOVE;
            INPUT      inputEvent = createInput(target, flag, true);

            if (SendInput(1, ref inputEvent, Marshal.SizeOf(typeof(INPUT))) == 0)
            {
                MessageBox.Show("Ha fallado el remplazo del evento en MouseHook. Codigo error -->" + Marshal.GetLastWin32Error());
            }
            return(false);
        }
コード例 #5
0
        MouseFlags GetButtonState(Curses.MouseEvent cev, bool pressed = false)
        {
            MouseFlags mf = default;

            switch (cev.ButtonState)
            {
            case Curses.Event.Button1Clicked:
                if (pressed)
                {
                    mf = MouseFlags.Button1Pressed;
                }
                else
                {
                    mf = MouseFlags.Button1Released;
                }
                break;

            case Curses.Event.Button2Clicked:
                if (pressed)
                {
                    mf = MouseFlags.Button2Pressed;
                }
                else
                {
                    mf = MouseFlags.Button2Released;
                }
                break;

            case Curses.Event.Button3Clicked:
                if (pressed)
                {
                    mf = MouseFlags.Button3Pressed;
                }
                else
                {
                    mf = MouseFlags.Button3Released;
                }
                break;

            case Curses.Event.Button1Released:
                mf = MouseFlags.Button1Clicked;
                break;

            case Curses.Event.Button2Released:
                mf = MouseFlags.Button2Clicked;
                break;

            case Curses.Event.Button3Released:
                mf = MouseFlags.Button3Clicked;
                break;
            }
            return(mf);
        }
コード例 #6
0
 private MouseFlags ProcessButtonReleasedEvent(Curses.MouseEvent cev, MouseFlags mf)
 {
     mf = (MouseFlags)cev.ButtonState;
     mouseHandler(ProcessButtonState(cev, mf));
     if (!cancelButtonClicked && LastMouseButtonPressed == null)
     {
         mf = GetButtonState(cev);
     }
     else
     {
         cancelButtonClicked = false;
     }
     return(mf);
 }
コード例 #7
0
        public static void MouseWheel(int clicks)
        {
            MouseInput input = new MouseInput();

            input.type      = (int)InputType.INPUT_MOUSE;
            input.mouseData = clicks;
            MouseFlags flags = MouseFlags.MOUSEEVENTF_WHEEL;

            input.dwFlags = (int)flags;
            Point c = Cursor.Position;

            input.dx = c.X;
            input.dy = c.Y;
            SendInput(input);
        }
コード例 #8
0
 private MouseFlags ProcessButtonClickedEvent(Curses.MouseEvent cev, MouseFlags mf)
 {
     LastMouseButtonPressed = cev.ButtonState;
     mf = GetButtonState(cev, true);
     mouseHandler(ProcessButtonState(cev, mf));
     if (LastMouseButtonPressed != null && LastMouseButtonPressed == cev.ButtonState)
     {
         mf = GetButtonState(cev, false);
         mouseHandler(ProcessButtonState(cev, mf));
         if (LastMouseButtonPressed != null && LastMouseButtonPressed == cev.ButtonState)
         {
             mf = (MouseFlags)cev.ButtonState;
         }
     }
     LastMouseButtonPressed = null;
     return(mf);
 }
コード例 #9
0
        public INPUT createInput(POINT pos, MouseFlags flag, bool automated = false)
        {
            INPUT mouseEvent = new INPUT()
            {
            };

            mouseEvent.tipo = TIPO_MOUSEVENT;
            //Si pongo de la manera directa sin MouseFlags.MOUSEEVENTF_ABSOLUTE en el parametro de flag, resulta que simplemente suma a la posición actual del raton.
            //La manera correcta es la siguiente
            mouseEvent.data.mouse.dx          = flag == MouseFlags.MOUSE_MOVE_ABSOLUTE ? Convert.ToInt32(pos.X) : Convert.ToInt32(pos.X * (65536.0f / SystemInfo.getSystemInfo(SystemInfo.SystemMetric.SM_CXSCREEN)));
            mouseEvent.data.mouse.dy          = flag == MouseFlags.MOUSE_MOVE_ABSOLUTE ? Convert.ToInt32(pos.Y) : Convert.ToInt32(pos.Y * (65536.0f / SystemInfo.getSystemInfo(SystemInfo.SystemMetric.SM_CYSCREEN)));
            mouseEvent.data.mouse.mouseData   = 0;
            mouseEvent.data.mouse.time        = 0;
            mouseEvent.data.mouse.dwExtraInfo = automated  ? new IntPtr(-1) : SystemInfo.GetMessageExtraInfo();  //Coloco esto como flag para saber cuando es automatizado //mouseEvent.data.mouse.dwExtraInfo = ControllerSystemInfo.GetMessageExtraInfo();
            mouseEvent.data.mouse.dwFlags     = (uint)flag;

            return(mouseEvent);
        }
コード例 #10
0
ファイル: CursesDriver.cs プロジェクト: kreghek/gui.cs
        static MouseFlags SetControlKeyStates(Curses.MouseEvent cev, MouseFlags mouseFlag)
        {
            if ((cev.ButtonState & Curses.Event.ButtonCtrl) != 0 && (mouseFlag & MouseFlags.ButtonCtrl) == 0)
            {
                mouseFlag |= MouseFlags.ButtonCtrl;
            }

            if ((cev.ButtonState & Curses.Event.ButtonShift) != 0 && (mouseFlag & MouseFlags.ButtonShift) == 0)
            {
                mouseFlag |= MouseFlags.ButtonShift;
            }

            if ((cev.ButtonState & Curses.Event.ButtonAlt) != 0 && (mouseFlag & MouseFlags.ButtonAlt) == 0)
            {
                mouseFlag |= MouseFlags.ButtonAlt;
            }
            return(mouseFlag);
        }
コード例 #11
0
ファイル: mouse.cs プロジェクト: steveshep/XmlNotepad
        public static void MouseWheel(AutomationWrapper w, int clicks)
        {
            var c = Cursor.Position;

            if (w != null)
            {
                c = w.PhysicalToLogicalPoint(c);
            }
            MouseInput input = new MouseInput();

            input.type      = (int)InputType.INPUT_MOUSE;
            input.mouseData = clicks;
            MouseFlags flags = MouseFlags.MOUSEEVENTF_WHEEL;

            input.dwFlags = (int)flags;
            input.dx      = c.X;
            input.dy      = c.Y;
            SendInput(input);
        }
コード例 #12
0
 private static MouseFlags AddMouseUpFlags(MouseFlags flags, MouseButtons buttons)
 {
     if ((buttons & MouseButtons.Left) != 0)
     {
         flags |= MouseFlags.MOUSEEVENTF_LEFTUP;
     }
     if ((buttons & MouseButtons.Right) != 0)
     {
         flags |= MouseFlags.MOUSEEVENTF_RIGHTUP;
     }
     if ((buttons & MouseButtons.Middle) != 0)
     {
         flags |= MouseFlags.MOUSEEVENTF_MIDDLEUP;
     }
     if ((buttons & MouseButtons.XButton1) != 0)
     {
         flags |= MouseFlags.MOUSEEVENTF_XUP;
     }
     return(flags);
 }
コード例 #13
0
        private static MouseFlags GetMouseDownFlags(MouseButtons buttons)
        {
            MouseFlags flags = 0;

            if ((buttons & MouseButtons.Left) != 0)
            {
                flags |= MouseFlags.MOUSEEVENTF_LEFTDOWN;
            }
            if ((buttons & MouseButtons.Right) != 0)
            {
                flags |= MouseFlags.MOUSEEVENTF_RIGHTDOWN;
            }
            if ((buttons & MouseButtons.Middle) != 0)
            {
                flags |= MouseFlags.MOUSEEVENTF_MIDDLEDOWN;
            }
            if ((buttons & MouseButtons.XButton1) != 0)
            {
                flags |= MouseFlags.MOUSEEVENTF_XDOWN;
            }
            return(flags);
        }
コード例 #14
0
        public uint SendMouseInput(int deltaX, int deltaY, int data, MouseFlags flags)
        {
            INPUT[] inputs = new INPUT[]
            {
                new INPUT
                {
                    type = InputFlags.INPUT_MOUSE,
                    u    = new InputUnion
                    {
                        mi = new MOUSEINPUT
                        {
                            dwFlags   = flags,
                            dx        = (int)deltaX,
                            dy        = (int)deltaY,
                            mouseData = data
                        }
                    }
                }
            };

            return(SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))));
        }
コード例 #15
0
 public static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
コード例 #16
0
 private static extern int mouse_event(MouseFlags dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
コード例 #17
0
        private static int LowLevelMouseHookCallback(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code < 0)
            {
                return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
            }

            MouseFlags flag = (MouseFlags)wParam;

            switch (flag)
            {
            case MouseFlags.WM_LBUTTONDOWN:
                Debug.WriteLine(MouseFlags.WM_LBUTTONDOWN);
                break;

            case MouseFlags.WM_LBUTTONUP:
                Debug.WriteLine(MouseFlags.WM_LBUTTONUP);
                break;

            case MouseFlags.WM_MOUSEMOVE:
                Debug.WriteLine(MouseFlags.WM_MOUSEMOVE);
                break;

            case MouseFlags.WM_MOUSEWHEEL:
                Debug.WriteLine(MouseFlags.WM_MOUSEWHEEL);
                break;

            case MouseFlags.WM_MOUSEHWHEEL:
                Debug.WriteLine(MouseFlags.WM_MOUSEHWHEEL);
                break;

            case MouseFlags.WM_RBUTTONDOWN:
                Debug.WriteLine(MouseFlags.WM_RBUTTONDOWN);
                break;

            case MouseFlags.WM_RBUTTONUP:
                Debug.WriteLine(MouseFlags.WM_RBUTTONUP);
                break;

            case MouseFlags.WM_XBUTTONDOWN:
                Debug.WriteLine(MouseFlags.WM_XBUTTONDOWN);
                break;

            case MouseFlags.WM_XBUTTONUP:
                Debug.WriteLine(MouseFlags.WM_XBUTTONUP);
                break;

            case MouseFlags.WM_XBUTTONDBLCLK:
                Debug.WriteLine(MouseFlags.WM_XBUTTONDBLCLK);
                break;

            case MouseFlags.WM_NCXBUTTONDOWN:
                Debug.WriteLine(MouseFlags.WM_NCXBUTTONDOWN);
                break;

            case MouseFlags.WM_NCXBUTTONUP:
                Debug.WriteLine(MouseFlags.WM_NCXBUTTONUP);
                break;

            case MouseFlags.WM_NCXBUTTONDBLCLK:
                Debug.WriteLine(MouseFlags.WM_NCXBUTTONDBLCLK);
                break;

            case MouseFlags.WM_MBUTTONDOWN:
                Debug.WriteLine(MouseFlags.WM_NCXBUTTONDBLCLK);
                break;

            case MouseFlags.WM_MBUTTONUP:
                Debug.WriteLine(MouseFlags.WM_MBUTTONUP);
                break;

            default:
                Debug.WriteLine("Unknown Flag: {0:X}", flag);
                break;
            }

            MouseStruct mouseStruct = Marshal.PtrToStructure <MouseStruct>(lParam);

            Debug.WriteLine(mouseStruct.point.x + ", " + mouseStruct.point.y);
            Debug.WriteLine(mouseStruct.mouseData);
            Debug.WriteLine(mouseStruct.flags);
            //Debug.WriteLine(mouseStruct.time);
            if (mouseStruct.dwExtraInfo.ToUInt32() != 0)
            {
                Debug.WriteLine(mouseStruct.dwExtraInfo);
            }
            Debug.WriteLine("");

            return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
        }
コード例 #18
0
        MouseEvent ToDriverMouse(Curses.MouseEvent cev)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            if (LastMouseButtonPressed != null && cev.ButtonState != Curses.Event.ReportMousePosition)
            {
                LastMouseButtonPressed = null;
                IsButtonPressed        = false;
            }


            if ((cev.ButtonState == Curses.Event.Button1Clicked || cev.ButtonState == Curses.Event.Button2Clicked ||
                 cev.ButtonState == Curses.Event.Button3Clicked) &&
                LastMouseButtonPressed == null)
            {
                IsButtonPressed = false;
                mouseFlag       = ProcessButtonClickedEvent(cev, mouseFlag);
            }
            else if (((cev.ButtonState == Curses.Event.Button1Pressed || cev.ButtonState == Curses.Event.Button2Pressed ||
                       cev.ButtonState == Curses.Event.Button3Pressed) && LastMouseButtonPressed == null) ||
                     IsButtonPressed && cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag = (MouseFlags)cev.ButtonState;
                if (cev.ButtonState != Curses.Event.ReportMousePosition)
                {
                    LastMouseButtonPressed = cev.ButtonState;
                }
                IsButtonPressed = true;

                if (cev.ButtonState == Curses.Event.ReportMousePosition)
                {
                    mouseFlag           = (MouseFlags)LastMouseButtonPressed | MouseFlags.ReportMousePosition;
                    point               = new Point();
                    cancelButtonClicked = true;
                }
                else
                {
                    point = new Point()
                    {
                        X = cev.X,
                        Y = cev.Y
                    };
                }

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

                            var view = Application.wantContinuousButtonPressedView;
                            if (view == null)
                            {
                                break;
                            }
                            if (IsButtonPressed && LastMouseButtonPressed != null && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
                            {
                                mouseHandler(me);
                                //mainLoop.Driver.Wakeup ();
                            }
                        }
                    });
                }
            }
            else if ((cev.ButtonState == Curses.Event.Button1Released || cev.ButtonState == Curses.Event.Button2Released ||
                      cev.ButtonState == Curses.Event.Button3Released))
            {
                mouseFlag       = ProcessButtonReleasedEvent(cev, mouseFlag);
                IsButtonPressed = false;
            }
            else if (cev.ButtonState == Curses.Event.Button4Pressed)
            {
                mouseFlag = MouseFlags.WheeledUp;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition && cev.X == point.X && cev.Y == point.Y)
            {
                mouseFlag = MouseFlags.WheeledDown;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag = MouseFlags.ReportMousePosition;
            }
            else
            {
                mouseFlag = (MouseFlags)cev.ButtonState;
            }

            point = new Point()
            {
                X = cev.X,
                Y = cev.Y
            };



            if (cev.ID != 0)
            {
                mouseFlag = MouseFlags.WheeledDown;
            }

            return(new MouseEvent()
            {
                X = cev.X,
                Y = cev.Y,
                //Flags = (MouseFlags)cev.ButtonState
                Flags = mouseFlag
            });
        }
 private static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, System.UIntPtr dwExtraInfo);
コード例 #20
0
ファイル: PointerModule.cs プロジェクト: ufouz1990/LeapIN
 public PointerMode(string n, MouseFlags f) : this(n, f, 0, 0)
 {
 }
コード例 #21
0
ファイル: WindowsDriver.cs プロジェクト: vCas/gui.cs
        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);
                }
            }
        }
コード例 #22
0
ファイル: ProcessControl.cs プロジェクト: JocysCom/PassGen
 public static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, UIntPtr dwExtraInfo);
コード例 #23
0
 public static extern int mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, uint dwExtraInfo);
コード例 #24
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
            });
        }
コード例 #25
0
ファイル: CursesDriver.cs プロジェクト: mrboring-forks/gui.cs
        MouseEvent ToDriverMouse(Curses.MouseEvent cev)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            if (LastMouseButtonPressed != null && cev.ButtonState != Curses.Event.ReportMousePosition)
            {
                LastMouseButtonPressed = null;
                IsButtonPressed        = false;
            }


            if ((cev.ButtonState == Curses.Event.Button1Clicked || cev.ButtonState == Curses.Event.Button2Clicked ||
                 cev.ButtonState == Curses.Event.Button3Clicked) &&
                LastMouseButtonPressed == null)
            {
                IsButtonPressed = false;
                mouseFlag       = ProcessButtonClickedEvent(cev);
            }
            else if (((cev.ButtonState == Curses.Event.Button1Pressed || cev.ButtonState == Curses.Event.Button2Pressed ||
                       cev.ButtonState == Curses.Event.Button3Pressed) && LastMouseButtonPressed == null) ||
                     IsButtonPressed && cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag = MapCursesButton(cev.ButtonState);
                if (cev.ButtonState != Curses.Event.ReportMousePosition)
                {
                    LastMouseButtonPressed = cev.ButtonState;
                }
                IsButtonPressed       = true;
                isReportMousePosition = false;

                if (cev.ButtonState == Curses.Event.ReportMousePosition)
                {
                    mouseFlag = MapCursesButton((Curses.Event)LastMouseButtonPressed) | MouseFlags.ReportMousePosition;
                    point     = new Point();
                    //cancelButtonClicked = true;
                }
                else
                {
                    point = new Point()
                    {
                        X = cev.X,
                        Y = cev.Y
                    };
                }

                if ((mouseFlag & MouseFlags.ReportMousePosition) == 0)
                {
                    Task.Run(async() => {
                        while (IsButtonPressed && LastMouseButtonPressed != null)
                        {
                            await Task.Delay(100);
                            var me = new MouseEvent()
                            {
                                X     = cev.X,
                                Y     = cev.Y,
                                Flags = mouseFlag
                            };

                            var view = Application.wantContinuousButtonPressedView;
                            if (view == null)
                            {
                                break;
                            }
                            if (IsButtonPressed && LastMouseButtonPressed != null && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
                            {
                                mouseHandler(me);
                                //mainLoop.Driver.Wakeup ();
                            }
                        }
                    });
                }
            }
            else if ((cev.ButtonState == Curses.Event.Button1Released || cev.ButtonState == Curses.Event.Button2Released ||
                      cev.ButtonState == Curses.Event.Button3Released))
            {
                mouseFlag       = ProcessButtonReleasedEvent(cev);
                IsButtonPressed = false;
            }
            else if (cev.ButtonState == Curses.Event.ButtonWheeledUp)
            {
                mouseFlag = MouseFlags.WheeledUp;
            }
            else if (cev.ButtonState == Curses.Event.ButtonWheeledDown)
            {
                mouseFlag = MouseFlags.WheeledDown;
            }
            else if ((cev.ButtonState & (Curses.Event.ButtonWheeledUp & Curses.Event.ButtonShift)) != 0)
            {
                mouseFlag = MouseFlags.WheeledLeft;
            }
            else if ((cev.ButtonState & (Curses.Event.ButtonWheeledDown & Curses.Event.ButtonShift)) != 0)
            {
                mouseFlag = MouseFlags.WheeledRight;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag             = MouseFlags.ReportMousePosition;
                isReportMousePosition = true;
            }
            else
            {
                mouseFlag = 0;
                var eFlags = cev.ButtonState;
                foreach (Enum value in Enum.GetValues(eFlags.GetType()))
                {
                    if (eFlags.HasFlag(value))
                    {
                        mouseFlag |= MapCursesButton((Curses.Event)value);
                    }
                }
            }

            mouseFlag = SetControlKeyStates(cev, mouseFlag);

            point = new Point()
            {
                X = cev.X,
                Y = cev.Y
            };

            return(new MouseEvent()
            {
                X = cev.X,
                Y = cev.Y,
                //Flags = MapCursesButton (cev.ButtonState)
                Flags = mouseFlag
            });
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: linqur/fish
 static extern void mouse_event(MouseFlags dwFlags, int dwData, UIntPtr dwExtraInfo);
コード例 #27
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
            });
        }
コード例 #28
0
 private static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, System.UIntPtr dwExtraInfo);
コード例 #29
0
ファイル: CursesDriver.cs プロジェクト: kreghek/gui.cs
        MouseEvent ToDriverMouse(Curses.MouseEvent cev)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            if (LastMouseButtonPressed != null && cev.ButtonState != Curses.Event.ReportMousePosition)
            {
                LastMouseButtonPressed = null;
                IsButtonPressed        = false;
            }


            if ((cev.ButtonState == Curses.Event.Button1Clicked || cev.ButtonState == Curses.Event.Button2Clicked ||
                 cev.ButtonState == Curses.Event.Button3Clicked) &&
                LastMouseButtonPressed == null)
            {
                IsButtonPressed = false;
                mouseFlag       = ProcessButtonClickedEvent(cev);
            }
            else if (((cev.ButtonState == Curses.Event.Button1Pressed || cev.ButtonState == Curses.Event.Button2Pressed ||
                       cev.ButtonState == Curses.Event.Button3Pressed) && LastMouseButtonPressed == null) ||
                     IsButtonPressed && cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag = MapCursesButton(cev.ButtonState);
                if (cev.ButtonState != Curses.Event.ReportMousePosition)
                {
                    LastMouseButtonPressed = cev.ButtonState;
                }
                IsButtonPressed       = true;
                isReportMousePosition = false;

                if (cev.ButtonState == Curses.Event.ReportMousePosition)
                {
                    mouseFlag = MapCursesButton((Curses.Event)LastMouseButtonPressed) | MouseFlags.ReportMousePosition;
                    point     = new Point();
                    //cancelButtonClicked = true;
                }
                else
                {
                    point = new Point()
                    {
                        X = cev.X,
                        Y = cev.Y
                    };
                }

                if ((mouseFlag & MouseFlags.ReportMousePosition) == 0)
                {
                    ProcessContinuousButtonPressedAsync(cev, mouseFlag).ConfigureAwait(false);
                }
            }
            else if ((cev.ButtonState == Curses.Event.Button1Released || cev.ButtonState == Curses.Event.Button2Released ||
                      cev.ButtonState == Curses.Event.Button3Released))
            {
                mouseFlag       = ProcessButtonReleasedEvent(cev);
                IsButtonPressed = false;
            }
            else if (cev.ButtonState == Curses.Event.ButtonWheeledUp)
            {
                mouseFlag = MouseFlags.WheeledUp;
            }
            else if (cev.ButtonState == Curses.Event.ButtonWheeledDown)
            {
                mouseFlag = MouseFlags.WheeledDown;
            }
            else if ((cev.ButtonState & (Curses.Event.ButtonWheeledUp & Curses.Event.ButtonShift)) != 0)
            {
                mouseFlag = MouseFlags.WheeledLeft;
            }
            else if ((cev.ButtonState & (Curses.Event.ButtonWheeledDown & Curses.Event.ButtonShift)) != 0)
            {
                mouseFlag = MouseFlags.WheeledRight;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag             = MouseFlags.ReportMousePosition;
                isReportMousePosition = true;
            }
            else
            {
                mouseFlag = 0;
                var eFlags = cev.ButtonState;
                foreach (Enum value in Enum.GetValues(eFlags.GetType()))
                {
                    if (eFlags.HasFlag(value))
                    {
                        mouseFlag |= MapCursesButton((Curses.Event)value);
                    }
                }
            }

            mouseFlag = SetControlKeyStates(cev, mouseFlag);

            point = new Point()
            {
                X = cev.X,
                Y = cev.Y
            };

            return(new MouseEvent()
            {
                X = cev.X,
                Y = cev.Y,
                //Flags = MapCursesButton (cev.ButtonState)
                Flags = mouseFlag
            });
        }
コード例 #30
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);
        }
コード例 #31
0
ファイル: Mouse.cs プロジェクト: grosbok/L2RBot
 public static void Simulate(MouseFlags commandFlags)//Point position)
 {
     Mouse_event((uint)commandFlags, 0, 0, 0, 0);
 }