Exemplo n.º 1
0
        internal void Execute(ref ControllerState state)
        {
            #region State Changes
            if (stateChange != null)
            {
                if (stateChange.toggle)
                {
                    if (state.inputMode == InputMode.Move)
                    {
                        state.inputMode = InputMode.Pointer;
                    }
                    else if (state.inputMode == InputMode.Pointer)
                    {
                        state.inputMode = InputMode.Move;
                    }
                }
                else if (stateChange.newMode != InputMode.None)
                {
                    state.inputMode = stateChange.newMode;
                }
            }
            #endregion

            #region Mouse Movements
            if (mouseMove != null)
            {
                if (mouseMove.commandTarget == CommandTarget.Cursor)
                {
                    if (mouseMove.moveType == MouseMoveType.Absolute)
                    {
                        state.cursorPosition.X = state.centerPosition.X + (int)(state.pointCommandValue.X * mouseMove.moveScale.X);
                        state.cursorPosition.Y = state.centerPosition.Y + (int)(state.pointCommandValue.Y * mouseMove.moveScale.Y);
                    }
                }
            }

            if (target == CommandTarget.TargetReticule)
            {
                VirtualMouse.MoveAbsolute(state.targetingReticulePosition.X, state.targetingReticulePosition.Y);
            }
            else if (target == CommandTarget.Cursor)
            {
                VirtualMouse.MoveAbsolute(state.cursorPosition.X, state.cursorPosition.Y);
            }
            else
            {
                //
            }
            #endregion


            #region Keys
            if (key.HasValue)
            {
                if (commandState == KeyboardMouseCommandState.Down)
                {
                    VirtualKeyboard.KeyDown(key.Value);
                }
                else
                {
                    VirtualKeyboard.KeyUp(key.Value);
                }
            }
            #endregion

            #region Mouse Buttons
            if (mouseButton.HasValue)
            {
                if (commandState == KeyboardMouseCommandState.Down)
                {
                    if (mouseButton.Value == MouseButtons.Left)
                    {
                        VirtualMouse.LeftDown();
                    }
                    else if (mouseButton.Value == MouseButtons.Right)
                    {
                        VirtualMouse.RightDown();
                    }
                }
                else
                {
                    if (mouseButton.Value == MouseButtons.Left)
                    {
                        VirtualMouse.LeftUp();
                    }
                    else if (mouseButton.Value == MouseButtons.Right)
                    {
                        VirtualMouse.RightUp();
                    }
                }
            }
            #endregion
        }
Exemplo n.º 2
0
        public void Update(GamePadState newState)
        {
            currentControllerState.connected = newState.IsConnected;

            if (!newState.IsConnected)
            {
                return;
            }

            if (currentControllerState.inputMode == InputMode.Move)
            {
                int DeltaX = (int)currentControllerState.cursorPosition.X - (int)center.X;
                int DeltaY = (int)currentControllerState.cursorPosition.Y - (int)center.Y;

                Vector2 deltaVector = new Vector2(DeltaX, DeltaY);
                deltaVector.Normalize();

                deltaVector *= 1000.0f;


                currentControllerState.centerPosition = new UIntVector((uint)(center.X + deltaVector.X), (uint)(center.Y + deltaVector.Y));
                // VirtualMouse.MoveAbsolute(center.X, center.Y);
            }
            else
            {
                //
            }



            foreach (ControllerInputBinding binding in bindings)
            {
                if (binding.button != 0)
                {
                    if (binding.buttonState == ControllerButtonState.OnDown)
                    {
                        if ((newState.IsButtonDown(binding.button)) && (lastState.IsButtonUp(binding.button)))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.OnUp)
                    {
                        if ((newState.IsButtonUp(binding.button)) && (lastState.IsButtonDown(binding.button)))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.WhileDown)
                    {
                        if (newState.IsButtonDown(binding.button))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.WhileUp)
                    {
                        if (newState.IsButtonUp(binding.button))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                }

                if (binding.trigger != null)
                {
                    if (binding.trigger.side == ControllerTrigger.Left)
                    {
                        if (binding.triggerState == ControllerTriggerState.OnDown)
                        {
                            if ((newState.Triggers.Left > binding.trigger.position) && (lastState.Triggers.Left < binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.OnUp)
                        {
                            if ((newState.Triggers.Left < binding.trigger.position) && (lastState.Triggers.Left > binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileDown)
                        {
                            if (newState.Triggers.Left > 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileUp)
                        {
                            if (newState.Triggers.Left == 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                    }
                    else if (binding.trigger.side == ControllerTrigger.Right)
                    {
                        if (binding.triggerState == ControllerTriggerState.OnDown)
                        {
                            if ((newState.Triggers.Right > binding.trigger.position) && (lastState.Triggers.Right < binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.OnUp)
                        {
                            if ((newState.Triggers.Right < binding.trigger.position) && (lastState.Triggers.Right > binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileDown)
                        {
                            if (newState.Triggers.Right > 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileUp)
                        {
                            if (newState.Triggers.Right == 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                    }
                }

                if (binding.stick != null)
                {
                    bool executeCommand;

                    if (binding.stick.side == ControllerStick.Left)
                    {
                        executeCommand = true;

                        if (binding.stick.newState == StickState.NotEqual)
                        {
                            if ((newState.ThumbSticks.Left.X == binding.stick.position.X) && (newState.ThumbSticks.Left.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.newState == StickState.Equal)
                        {
                            if ((newState.ThumbSticks.Left.X != binding.stick.position.X) || (newState.ThumbSticks.Left.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (binding.stick.oldState == StickState.NotEqual)
                        {
                            if ((lastState.ThumbSticks.Left.X == binding.stick.position.X) && (lastState.ThumbSticks.Left.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.oldState == StickState.Equal)
                        {
                            if ((lastState.ThumbSticks.Left.X != binding.stick.position.X) || (lastState.ThumbSticks.Left.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (executeCommand)
                        {
                            Microsoft.Xna.Framework.Vector2 inputCommandValue = new Microsoft.Xna.Framework.Vector2(newState.ThumbSticks.Left.X, newState.ThumbSticks.Left.Y);
                            enqueueCommands(binding, currentControllerState, inputCommandValue);
                        }
                    }
                    else if (binding.stick.side == ControllerStick.Right)
                    {
                        executeCommand = true;

                        if (binding.stick.newState == StickState.NotEqual)
                        {
                            if ((newState.ThumbSticks.Right.X == binding.stick.position.X) && (newState.ThumbSticks.Right.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.newState == StickState.Equal)
                        {
                            if ((newState.ThumbSticks.Right.X != binding.stick.position.X) || (newState.ThumbSticks.Right.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (binding.stick.oldState == StickState.NotEqual)
                        {
                            if ((lastState.ThumbSticks.Right.X == binding.stick.position.X) && (lastState.ThumbSticks.Right.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.oldState == StickState.Equal)
                        {
                            if ((lastState.ThumbSticks.Right.X != binding.stick.position.X) || (lastState.ThumbSticks.Right.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (executeCommand)
                        {
                            Microsoft.Xna.Framework.Vector2 inputCommandValue = new Microsoft.Xna.Framework.Vector2(newState.ThumbSticks.Right.X, newState.ThumbSticks.Right.Y);
                            enqueueCommands(binding, currentControllerState, inputCommandValue);
                        }
                    }
                }
            }


            while (stateChangeCommands.Count > 0)
            {
                VirtualKeyboard.AllUp();

                currentControllerState.targetingReticulePosition = currentControllerState.centerPosition;
                currentControllerState.cursorPosition            = currentControllerState.centerPosition;

                stateChangeCommands.Dequeue().Execute(ref currentControllerState);
            }

            while (cursorMoveCommands.Count > 0)
            {
                cursorMoveCommands.Dequeue().Execute(ref currentControllerState);
            }



            if (centerRandomTargetedCommands.Count > 0)
            {
                int DeltaX = (int)currentControllerState.cursorPosition.X - (int)center.X;
                int DeltaY = (int)currentControllerState.cursorPosition.Y - (int)center.Y;

                Vector2 deltaVector = new Vector2(DeltaX, DeltaY);
                deltaVector.Normalize();

                deltaVector *= 1000.0f;


                UIntVector centerOffset = new UIntVector((uint)(center.X + deltaVector.X), (uint)(center.Y + deltaVector.Y));
                VirtualMouse.MoveAbsolute(centerOffset.X, centerOffset.Y);
            }
            while (centerRandomTargetedCommands.Count > 0)
            {
                centerRandomTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }



            if (reticuleTargetedCommands.Count > 0)
            {
                if ((currentControllerState.targetingReticulePosition.X == currentControllerState.centerPosition.X) && (currentControllerState.targetingReticulePosition.Y == currentControllerState.centerPosition.Y))
                {
                    VirtualMouse.MoveAbsolute(currentControllerState.cursorPosition.X, currentControllerState.cursorPosition.Y);
                }
                else
                {
                    VirtualMouse.MoveAbsolute(currentControllerState.targetingReticulePosition.X, currentControllerState.targetingReticulePosition.Y);
                }
            }

            Thread.Sleep(10);

            while (reticuleTargetedCommands.Count > 0)
            {
                reticuleTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }

            //if ((currentControllerState.inputMode != InputMode.None) && (currentControllerState.inputMode != InputMode.Pointer))
            if (currentControllerState.inputMode != InputMode.None)
            {
                VirtualMouse.MoveAbsolute(currentControllerState.cursorPosition.X, currentControllerState.cursorPosition.Y);
            }
            while (cursorTargetedCommands.Count > 0)
            {
                cursorTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }


            //if ((currentControllerState.inputMode != InputMode.None) && (currentControllerState.inputMode != InputMode.Pointer))



            while (untargetedCommands.Count > 0)
            {
                untargetedCommands.Dequeue().Execute(ref currentControllerState);
            }

            lastState = newState;
        }