예제 #1
0
        private void SimulateGestureBtnEvent(GestureBtnEventType eventType, int x, int y)
        {
            const int CLICK_PRESS_RELEASE_INTERVAL = 10;

            Debug.WriteLine("SimulateMouseEvent: " + _gestureBtn + " " + eventType);
            _simulatingMouse = true;

            User32.SetCursorPos(x, y);

            var mouseSwapped = Native.IsMouseButtonSwapped();

            switch (_gestureBtn)
            {
            case GestureButtons.RightButton:
                if (mouseSwapped)
                {
                    switch (eventType)
                    {
                    case GestureBtnEventType.UP:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;

                    case GestureBtnEventType.DOWN:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;

                    case GestureBtnEventType.CLICK:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;
                    }
                }
                else
                {
                    switch (eventType)
                    {
                    case GestureBtnEventType.UP:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;

                    case GestureBtnEventType.DOWN:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;

                    case GestureBtnEventType.CLICK:
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                        User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                        break;
                    }
                }
                break;

            case GestureButtons.MiddleButton:
                switch (eventType)
                {
                case GestureBtnEventType.UP:
                    User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);

                    break;

                case GestureBtnEventType.DOWN:
                    User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);

                    break;

                case GestureBtnEventType.CLICK:
                    User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                    Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                    User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                    break;
                }
                break;
            }
            _simulatingMouse = false;
        }
예제 #2
0
        private void SimulateGestureBtnEvent(GestureBtnEventType eventType, int x, int y)
        {
            const int CLICK_PRESS_RELEASE_INTERVAL = 10;

            Debug.WriteLine("SimulateMouseEvent: " + _gestureBtn + " " + eventType);
            _simulatingMouse = true;

            User32.SetCursorPos(x, y);

            var mouseSwapped = Native.IsMouseButtonSwapped();

            switch (_gestureBtn)
            {
                case GestureButtons.RightButton:
                    if (mouseSwapped)
                    {
                        switch (eventType)
                        {
                            case GestureBtnEventType.UP:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                            case GestureBtnEventType.DOWN:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                            case GestureBtnEventType.CLICK:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                        }
                    }
                    else
                    {
                        switch (eventType)
                        {
                            case GestureBtnEventType.UP:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                            case GestureBtnEventType.DOWN:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                            case GestureBtnEventType.CLICK:
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                                User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                                break;
                        }
                    }
                    break;
                case GestureButtons.MiddleButton:
                    switch (eventType)
                    {
                        case GestureBtnEventType.UP:
                            User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);

                            break;
                        case GestureBtnEventType.DOWN:
                            User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);

                            break;
                        case GestureBtnEventType.CLICK:
                            User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                            Thread.Sleep(CLICK_PRESS_RELEASE_INTERVAL);
                            User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
                            break;
                    }
                    break;
            }
            _simulatingMouse = false;
        }
예제 #3
0
        private void SimulateGestureBtnEvent(GestureBtnEventType eventType, int x, int y)
        {
            Debug.WriteLine("SimulateMouseEvent: " + _gestureBtn + " " + eventType);
            _simulatingMouse = true;

            var mouseSwapped = Native.GetSystemMetrics(Native.SystemMetric.SM_SWAPBUTTON) != 0;

            Native.POINT curPos;
            Native.GetCursorPos(out curPos);

            User32.MOUSEEVENTF events = 0;

            switch (_gestureBtn)
            {
            case GestureButtons.RightButton:
                if (mouseSwapped)
                {
                    switch (eventType)
                    {
                    case GestureBtnEventType.UP:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP;
                        break;

                    case GestureBtnEventType.DOWN:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN;
                        break;

                    case GestureBtnEventType.CLICK:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN | User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP;
                        break;
                    }
                }
                else
                {
                    switch (eventType)
                    {
                    case GestureBtnEventType.UP:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP;
                        break;

                    case GestureBtnEventType.DOWN:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN;
                        break;

                    case GestureBtnEventType.CLICK:
                        events = User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTDOWN | User32.MOUSEEVENTF.MOUSEEVENTF_RIGHTUP;
                        break;
                    }
                }
                break;

            case GestureButtons.MiddleButton:
                switch (eventType)
                {
                case GestureBtnEventType.UP:
                    events = User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP;
                    break;

                case GestureBtnEventType.DOWN:
                    events = User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN;
                    break;

                case GestureBtnEventType.CLICK:
                    events = User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEDOWN | User32.MOUSEEVENTF.MOUSEEVENTF_MIDDLEUP;
                    break;
                }
                break;
            }

            User32.SetCursorPos(x, y);
            //User32.SetMessageExtraInfo(new IntPtr(MOUSE_EVENT_EXTRA_SIMULATED));
            User32.mouse_event(events, x, y, 0, MOUSE_EVENT_EXTRA_SIMULATED);
            //var sim = new InputSimulator();
            //sim.Mouse.RightButtonDown();
            //sim.Mouse.Sleep(10);
            //sim.Mouse.RightButtonUp();

            _simulatingMouse = false;
        }