Ejemplo n.º 1
0
        public override bool Execute(ref ControllerState state)
        {
            if (base.Execute(ref state))
            {
                #region Keys
                if (key.HasValue)
                {
                    if (commandState == ButtonState.Down)
                    {
                        VirtualKeyboard.KeyDown(key.Value);
                    }
                    else
                    {
                        VirtualKeyboard.KeyUp(key.Value);
                    }
                }
                #endregion

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

#if !DEBUG
            try
            {
#endif
            D360.Main.self.Init();
#if !DEBUG
        }
        catch (Exception exception)
        {
            Program.WriteToLog(exception);
        }
#endif
            // Cleanup just in case
            VirtualKeyboard.ReleaseAll();
        }
Ejemplo n.º 3
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;
        }