Esempio n. 1
0
        public Settings()
        {
            InitializeComponent();

            enableControlCheck.Checked = ControlState.GetSystemEnabled();

            controller0CheckBox.Checked = ControlState.GetControllerEnabled(0);
            controller1CheckBox.Checked = ControlState.GetControllerEnabled(1);
            controller2CheckBox.Checked = ControlState.GetControllerEnabled(2);
            controller3CheckBox.Checked = ControlState.GetControllerEnabled(3);
        }
Esempio n. 2
0
        //when the application loads
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //hide the window and the taskbar icon
            Visible       = false;
            ShowInTaskbar = false;

            //run the controller code
            bool   run = true;
            Thread t   =
                new Thread(
                    delegate() {
                while (run)
                {
                    ControllerWork.Update();
                    KeyboardWork.Update();
                    Thread.Sleep(1000 / 60);
                }
            }
                    );

            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            //run the loop here
            while (!this.IsDisposed)
            {
                if (ControlState.GetSystemEnabled())
                {
                    _icon.Icon = XMouse.Properties.Resources.trayIcon_sm_enabled;
                }
                else
                {
                    _icon.Icon = XMouse.Properties.Resources.trayIcon_sm_disabled;
                }

                //allow the form app to call it events
                Application.DoEvents();

                Thread.Sleep(200);
            }

            //stop the thread
            run = false;
        }
        //do the work needed to run the controller and mouse
        public static void Update()
        {
            //if (KeyboardRobot.GetKey(27)) Application.Exit(); // quit the application if escape is pressed

            // Reset stick positions
            _rightStick.X = _leftStick.X = _rightStick.Y = _leftStick.Y = 0;

            // move mouse
            Vector2 mouseMovement = Vector2.Zero;
            Vector2 scrollAmount  = Vector2.Zero;

            // store the button states -1 is pressed, 1 is up, 0 is nochange
            float rTrigger = 0.0f;
            float lTrigger = 0.0f;

            // go through every controller to check inputs
            for (int i = 0; i < 4; i++)
            {
                GamePadState gps  = GamePad.GetState((PlayerIndex)i, GamePadDeadZone.Circular);
                GamePadState pgps = _prevGamePadStates[i];


                // check if enable key combo is enabled
                if (IsEnableToggleComboPressed(gps) && !IsEnableToggleComboPressed(pgps))
                {
                    ControlState.ToggleSystemEnabled();

                    // store they previous state
                    _prevGamePadStates[i] = gps;
                    break;
                }

                //check if the quit key combo is enabled
                if (IsCtrlQComboPressed(gps) && !IsCtrlQComboPressed(pgps))
                {
                    KeyboardRobot.PressKey(0xA2);
                    KeyboardRobot.PressKey('q');
                    KeyboardRobot.ReleaseKey('q');
                    KeyboardRobot.ReleaseKey(0xA2);
                }

                // don't do anything if the player isn't enabled or if the entire system isn't enabled
                if (!ControlState.GetControllerEnabled(i) || !ControlState.GetSystemEnabled())
                {
                    _prevGamePadStates[i] = gps;
                    continue;
                }

                // save stick states
                _rightStick += gps.ThumbSticks.Right;
                _leftStick  += gps.ThumbSticks.Left;

                // store stick amount for mouse movement
                mouseMovement += gps.ThumbSticks.Left;
                scrollAmount  += gps.ThumbSticks.Right;

                // store the largest trigger value
                if (rTrigger < gps.Triggers.Right)
                {
                    rTrigger = gps.Triggers.Right;
                }
                if (lTrigger < gps.Triggers.Left)
                {
                    lTrigger = gps.Triggers.Left;
                }


                // If we're in mouse control
                if (!ControlState.isTyping)
                {
                    // MOUSE CLICKS //
                    // left click when a pressed
                    if (KeyPressed(gps, pgps, Buttons.A))
                    {
                        MouseRobot.PressButton(0);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.A))
                    {
                        MouseRobot.ReleaseButton(0);
                    }

                    // right click when b is pressed
                    if (KeyPressed(gps, pgps, Buttons.B))
                    {
                        MouseRobot.PressButton(1);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.B))
                    {
                        MouseRobot.ReleaseButton(1);
                    }

                    // middle click when y is pressed
                    if (KeyPressed(gps, pgps, Buttons.Y))
                    {
                        MouseRobot.PressButton(2);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.Y))
                    {
                        MouseRobot.ReleaseButton(2);
                    }

                    // ENTER KEY //
                    // press enter key when start is pressed
                    if (KeyPressed(gps, pgps, Buttons.Start))
                    {
                        KeyboardRobot.PressKey(13);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.Start))
                    {
                        KeyboardRobot.ReleaseKey(13);
                    }
                }
                else
                {
                    // Toggle they alt character set
                    if (KeyPressed(gps, pgps, Buttons.LeftShoulder))
                    {
                        ControlState.ToggleAltCharacters();
                    }

                    if (KeyPressed(gps, pgps, Buttons.Y))
                    {
                        ControlState.ToggleAltCharacters();
                        KeyboardWork.firstButtonAction(ControlState.Y_BUTTON, true);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.Y))
                    {
                        KeyboardWork.firstButtonAction(ControlState.Y_BUTTON, false);
                    }

                    // backspace when X is pressed
                    if (KeyPressed(gps, pgps, Buttons.X))
                    {
                        KeyboardRobot.PressKey(KeyboardRobot.BACKSPACE_KEY);
                        KeyboardWork.firstButtonAction(ControlState.X_BUTTON, true);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.X))
                    {
                        KeyboardRobot.ReleaseKey(KeyboardRobot.BACKSPACE_KEY);
                        KeyboardWork.firstButtonAction(ControlState.X_BUTTON, false);
                    }

                    // space when A is pressed
                    if (KeyPressed(gps, pgps, Buttons.A))
                    {
                        KeyboardRobot.PressKey(' ');
                        KeyboardWork.firstButtonAction(ControlState.A_BUTTON, true);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.A))
                    {
                        KeyboardRobot.ReleaseKey(' ');
                        KeyboardWork.firstButtonAction(ControlState.A_BUTTON, false);
                    }

                    // enter when B is pressed
                    if (KeyPressed(gps, pgps, Buttons.B))
                    {
                        KeyboardRobot.PressKey(KeyboardRobot.ENTER_KEY);
                        KeyboardWork.firstButtonAction(ControlState.B_BUTTON, true);
                    }
                    else if (KeyReleased(gps, pgps, Buttons.B))
                    {
                        KeyboardRobot.ReleaseKey(KeyboardRobot.ENTER_KEY);
                        KeyboardWork.firstButtonAction(ControlState.B_BUTTON, false);
                    }
                }

                // For both key states
                // TOGGLE TYPING STATE //
                if (KeyPressed(gps, pgps, Buttons.LeftStick))
                {
                    ControlState.isTyping = !ControlState.isTyping;
                }
                // ARROW KEYS //
                // Left Arrow when left DPad
                if (KeyPressed(gps, pgps, Buttons.DPadLeft))
                {
                    KeyboardRobot.PressKey(37);
                }
                else if (KeyReleased(gps, pgps, Buttons.DPadLeft))
                {
                    KeyboardRobot.ReleaseKey(37);
                }
                // Right Arrow when right dpad
                if (KeyPressed(gps, pgps, Buttons.DPadRight))
                {
                    KeyboardRobot.PressKey(39);
                }
                else if (KeyReleased(gps, pgps, Buttons.DPadRight))
                {
                    KeyboardRobot.ReleaseKey(39);
                }
                // Up Arrow
                if (KeyPressed(gps, pgps, Buttons.DPadUp))
                {
                    KeyboardRobot.PressKey(38);
                }
                else if (KeyReleased(gps, pgps, Buttons.DPadUp))
                {
                    KeyboardRobot.ReleaseKey(38);
                }
                // Down Arrow
                if (KeyPressed(gps, pgps, Buttons.DPadDown))
                {
                    KeyboardRobot.PressKey(40);
                }
                else if (KeyReleased(gps, pgps, Buttons.DPadDown))
                {
                    KeyboardRobot.ReleaseKey(40);
                }

                // store they previous state
                _prevGamePadStates[i] = gps;
            }

            // don't do anything if the system is not enabled
            if (!ControlState.GetSystemEnabled())
            {
                return;
            }
            if (ControlState.isTyping)
            {
                return;
            }

            // super speed if right trigger is pressed
            mouseMovement *= 30;
            mouseMovement -= rTrigger * mouseMovement * .7f;
            mouseMovement -= lTrigger * mouseMovement * .7f;

            scrollAmount *= 15;
            MouseRobot.Scroll((int)scrollAmount.Y);

            // moves the mouse
            MouseRobot.MoveMouse((int)mouseMovement.X, -(int)mouseMovement.Y);
        }