Exemple #1
0
        /// <summary>
        /// Get the value as a boolean
        /// </summary>
        public bool GetValue(KeyboardMouseState inputState)
        {
            if (!inputState.WindowFocused)
            {
                return(false);
            }

            if (_usemouse)
            {
                switch (_mouse)
                {
                case MouseInput.LeftButton:
                    return(inputState.MouseState.LeftButton == ButtonState.Pressed);

                case MouseInput.MiddleButton:
                    return(inputState.MouseState.MiddleButton == ButtonState.Pressed);

                case MouseInput.RightButton:
                    return(inputState.MouseState.RightButton == ButtonState.Pressed);

                case MouseInput.XButton1:
                    return(inputState.MouseState.XButton1 == ButtonState.Pressed);

                case MouseInput.XButton2:
                    return(inputState.MouseState.XButton2 == ButtonState.Pressed);
                }
                throw new ArgumentException();
            }
            else
            {
                return(inputState.KeyboardState.IsKeyDown(_key));
            }
        }
Exemple #2
0
        private void UpdateState(long tick, KeyboardMouseState keyboardMouseState, KeyboardMouseMapping mapping)
        {
            InputButtons.AButton.SetState(mapping.A.GetValue(keyboardMouseState), tick);
            InputButtons.BButton.SetState(mapping.B.GetValue(keyboardMouseState), tick);
            InputButtons.XButton.SetState(mapping.X.GetValue(keyboardMouseState), tick);
            InputButtons.YButton.SetState(mapping.Y.GetValue(keyboardMouseState), tick);

            InputButtons.DpadDButton.SetState(mapping.DpadDown.GetValue(keyboardMouseState), tick);
            InputButtons.DpadUButton.SetState(mapping.DpadUp.GetValue(keyboardMouseState), tick);
            InputButtons.DpadLButton.SetState(mapping.DpadLeft.GetValue(keyboardMouseState), tick);
            InputButtons.DpadRButton.SetState(mapping.DpadRight.GetValue(keyboardMouseState), tick);

            InputButtons.ShoulderLButton.SetState(mapping.LeftShoulder.GetValue(keyboardMouseState), tick);
            InputButtons.ShoulderRButton.SetState(mapping.RightShoulder.GetValue(keyboardMouseState), tick);

            InputButtons.BackButton.SetState(mapping.Back.GetValue(keyboardMouseState), tick);
            InputButtons.StartButton.SetState(mapping.Start.GetValue(keyboardMouseState), tick);
            InputButtons.LeftStickClickButton.SetState(mapping.LeftStickClick.GetValue(keyboardMouseState), tick);
            InputButtons.RightStickClickButton.SetState(mapping.RightStickClick.GetValue(keyboardMouseState), tick);

            InputTriggers.LeftTriggerFloat  = mapping.LeftTrigger.GetValue(keyboardMouseState, false);
            InputTriggers.RightTriggerFloat = mapping.RightTrigger.GetValue(keyboardMouseState, false);

            var v = new Vector2();

            v.Y = mapping.LeftStickForward.GetValue(keyboardMouseState, false) +
                  mapping.LeftStickBackward.GetValue(keyboardMouseState, true);
            v.X = mapping.LeftStickLeft.GetValue(keyboardMouseState, true) +
                  mapping.LeftStickRight.GetValue(keyboardMouseState, false);
            InputThumbSticks.LeftStickVector = v;

            v.Y = mapping.RightStickForward.GetValue(keyboardMouseState, false) +
                  mapping.RightStickBackward.GetValue(keyboardMouseState, true);
            v.X = mapping.RightStickLeft.GetValue(keyboardMouseState, true) +
                  mapping.RightStickRight.GetValue(keyboardMouseState, false);
            InputThumbSticks.RightStickVector = v;
        }
Exemple #3
0
        /// <summary>
        /// Get the value as a float
        /// </summary>
        public float GetValue(KeyboardMouseState inputState, bool invert)
        {
            if (!inputState.WindowFocused)
            {
                return(0);
            }

            KeyboardState ks = inputState.KeyboardState;
            MouseState    ms = inputState.MouseState;

            if (_usemouse)
            {
                float val = 0;
                switch (_mouse)
                {
                case MouseInput.LeftButton:
                    val = ms.LeftButton == ButtonState.Pressed ? 1 : 0;
                    break;

                case MouseInput.MiddleButton:
                    val = ms.MiddleButton == ButtonState.Pressed ? 1 : 0;
                    break;

                case MouseInput.RightButton:
                    val = ms.RightButton == ButtonState.Pressed ? 1 : 0;
                    break;

                case MouseInput.ScrollWheel:
                    if (invert)
                    {
                        return(0);
                    }
                    val = ms.ScrollWheelValue / 640.0f;
                    break;

                case MouseInput.XButton1:
                    val = ms.XButton1 == ButtonState.Pressed ? 1 : 0;
                    break;

                case MouseInput.XButton2:
                    val = ms.XButton2 == ButtonState.Pressed ? 1 : 0;
                    break;

                case MouseInput.XAxis:
                    if (invert)
                    {
                        return(0);
                    }
                    val = (ms.X - inputState.MousePositionPrevious.X) / 8.0f;
                    break;

                case MouseInput.YAxis:
                    if (invert)
                    {
                        return(0);
                    }
                    val = (ms.Y - inputState.MousePositionPrevious.Y) / -8.0f;
                    break;
                }

                if (invert)
                {
                    return(-val);
                }
                return(val);
            }
            else
            {
                if (ks.IsKeyDown(_key))
                {
                    if (invert)
                    {
                        return(-1);
                    }
                    return(1);
                }
                return(0);
            }
        }
Exemple #4
0
        private void UpdateState(long tick, KeyboardMouseState keyboardMouseState, KeyboardMouseMapping mapping)
        {
            InputButtons.AButton.SetState(mapping.A.GetValue(keyboardMouseState), tick);
            InputButtons.BButton.SetState(mapping.B.GetValue(keyboardMouseState), tick);
            InputButtons.XButton.SetState(mapping.X.GetValue(keyboardMouseState), tick);
            InputButtons.YButton.SetState(mapping.Y.GetValue(keyboardMouseState), tick);

            InputButtons.DpadDButton.SetState(mapping.DpadDown.GetValue(keyboardMouseState), tick);
            InputButtons.DpadUButton.SetState(mapping.DpadUp.GetValue(keyboardMouseState), tick);
            InputButtons.DpadLButton.SetState(mapping.DpadLeft.GetValue(keyboardMouseState), tick);
            InputButtons.DpadRButton.SetState(mapping.DpadRight.GetValue(keyboardMouseState), tick);

            InputButtons.ShoulderLButton.SetState(mapping.LeftShoulder.GetValue(keyboardMouseState), tick);
            InputButtons.ShoulderRButton.SetState(mapping.RightShoulder.GetValue(keyboardMouseState), tick);

            InputButtons.BackButton.SetState(mapping.Back.GetValue(keyboardMouseState), tick);
            InputButtons.StartButton.SetState(mapping.Start.GetValue(keyboardMouseState), tick);
            InputButtons.LeftStickClickButton.SetState(mapping.LeftStickClick.GetValue(keyboardMouseState), tick);
            InputButtons.RightStickClickButton.SetState(mapping.RightStickClick.GetValue(keyboardMouseState), tick);

            InputTriggers.LeftTriggerFloat = mapping.LeftTrigger.GetValue(keyboardMouseState, false);
            InputTriggers.RightTriggerFloat = mapping.RightTrigger.GetValue(keyboardMouseState, false);

            var v = new Vector2();

            v.Y = mapping.LeftStickForward.GetValue(keyboardMouseState, false) +
                  mapping.LeftStickBackward.GetValue(keyboardMouseState, true);
            v.X = mapping.LeftStickLeft.GetValue(keyboardMouseState, true) +
                  mapping.LeftStickRight.GetValue(keyboardMouseState, false);
            InputThumbSticks.LeftStickVector = v;

            v.Y = mapping.RightStickForward.GetValue(keyboardMouseState, false) +
                  mapping.RightStickBackward.GetValue(keyboardMouseState, true);
            v.X = mapping.RightStickLeft.GetValue(keyboardMouseState, true) +
                  mapping.RightStickRight.GetValue(keyboardMouseState, false);
            InputThumbSticks.RightStickVector = v;
        }