Esempio n. 1
0
        private void UnassignButton(GamepadButtons button)
        {
            switch (button)
            {
            case GamepadButtons.Aux1:
                aux1_button.Content = "Unassigned";
                break;

            case GamepadButtons.Aux2:
                aux2_button.Content = "Unassigned";
                break;

            case GamepadButtons.Aux3:
                aux3_button.Content = "Unassigned";
                break;

            case GamepadButtons.Aux4:
                aux4_button.Content = "Unassigned";
                break;

            default:
                return;
            }

            this.assignedButtons.Remove(button);
            SettingsManager.Instance.RemoveButtonAssignment(button);
        }
Esempio n. 2
0
        public void SetHit(GamepadButtons button)
        {
            if (!KeyBindings.ContainsKey(button))
            {
                return;
            }

            if (!HitBindings.ContainsKey(KeyBindings[button]))
            {
                return;
            }

            ushort hitsAmount = HitBindings[KeyBindings[button]];

            if (Scores + hitsAmount < short.MaxValue)
            {
                Scores += hitsAmount;
            }

            _setHitAction?.Invoke();

            if (SoundBindings.ContainsKey(KeyBindings[button]))
            {
                string soundFile = SoundBindings[KeyBindings[button]];

                if (!string.IsNullOrEmpty(soundFile) && !string.IsNullOrWhiteSpace(soundFile))
                {
                    _soundAction(soundFile);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Returns true if specified <paramref name="button"/> pressed on gamepad of specified player
 /// </summary>
 /// <param name="button">Button to check</param>
 /// <param name="gamepadNumber">Gamepad number</param>
 /// <returns></returns>
 public static bool IsButtonDown(GamepadButtons button, GamepadNumbers gamepadNumber)
 {
     if (GamepadInstance.IsDeviceConnected)
     {
         if (GamepadInstance.IsSupported)
         {
             if (GetState(gamepadNumber).Gamepad.Buttons == (GetState(gamepadNumber).Gamepad.Buttons | (XInput.GamepadButtonFlags)button))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 4
0
        private bool IsButtonJustPressed(GamepadButtons selection)
        {
            bool newSelectionPressed = (selection == (_currentReading.Buttons & selection));
            bool oldSelectionPressed = (selection == (_previousReading.Buttons & selection));

            return(newSelectionPressed && !oldSelectionPressed);
        }
Esempio n. 5
0
        public bool isThumbPostionInsideRadius(GamepadButtons buttonType, double currentThumbX, double currentThumbY, double tol)
        {
            double radius = 0.0;

            radius = Math.Sqrt(currentThumbX * currentThumbX + currentThumbY * currentThumbY);

            if (buttonType == GamepadButtons.RightThumb)
            {
                if ((_rightThumbRadius <= radius + tol) && (_rightThumbRadius >= radius - tol))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                if ((_leftThumbRadius <= radius + tol) && (_leftThumbRadius >= radius - tol))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Esempio n. 6
0
        private async Task ProcessButtons(GamepadButtons buttons)
        {
            switch (buttons)
            {
            case GamepadButtons.A: await OnAButton(); break;

            case GamepadButtons.B: await OnBButton(); break;

            case GamepadButtons.X: OnXButton(); break;

            case GamepadButtons.Y: OnYButton(); break;

            case GamepadButtons.LeftShoulder: OnLeftShoulderButton(); break;

            case GamepadButtons.RightShoulder: OnRightShoulderButton(); break;

            case GamepadButtons.DPadUp: OnDPadUpButton(); break;

            case GamepadButtons.DPadDown: OnDPadDownButton(); break;

            case GamepadButtons.DPadLeft: OnDPadLeftButton(); break;

            case GamepadButtons.DPadRight: OnDPadRightButton(); break;

            case GamepadButtons.Menu: OnMenuButton(); break;

            case GamepadButtons.LeftThumbstick: OnLeftThumbstickButton(); break;

            case GamepadButtons.RightThumbstick: OnRightThumbstickButton(); break;
            }
        }
Esempio n. 7
0
        private void AssignButton(GamepadButtons button, VirtualKey key)
        {
            switch (button)
            {
            case GamepadButtons.Aux1:
                aux1_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux2:
                aux2_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux3:
                aux3_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux4:
                aux4_button.Content = key.ToString();
                break;

            default:
                return;
            }

            this.assignedButtons[button] = key;
            SettingsManager.Instance.SaveButtonAssignment(this.assignedGamepadButton, key);
        }
Esempio n. 8
0
        public InputBinding(string name, Keys?keyboardKey = null, MouseButton?mouseButton = null, Buttons?gamepadButton = null, Axis?gamepadAxis = null)
        {
            Name = name;

            KeyboardKeys = new();
            if (keyboardKey != null)
            {
                KeyboardKeys.Add(new() { keyboardKey.Value });
            }
            MouseButtons = new();
            if (mouseButton != null)
            {
                MouseButtons.Add(mouseButton.Value);
            }
            GamepadButtons = new();
            if (gamepadButton != null)
            {
                GamepadButtons.Add(gamepadButton.Value);
            }
            GamepadAxis = new();
            if (gamepadAxis != null)
            {
                GamepadAxis.Add(gamepadAxis.Value);
            }
        }
Esempio n. 9
0
 public GamepadButtonDown(TimeSpan buttonDownTime,
                          GamepadButtons gamepadButtonOne,
                          GamepadButtons gamepadButtonTwo)
 {
     _buttonDownTime   = buttonDownTime;
     _gamepadButtonOne = gamepadButtonOne;
     _gamepadButtonTwo = gamepadButtonTwo;
 }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        public bool IsKeyPressed(GamepadButtons button)
        {
            if (((int)state.Gamepad.Buttons & (int)button) != 0)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        public void PerformAction(GamepadButtons button)
        {
            MainActionTypes?actionType = _actionsProvider.GetAction(button);

            if (actionType.HasValue)
            {
                _actionHandler.PerformAction(actionType.Value);
            }
        }
Esempio n. 12
0
 public void AddScoresKeyBinding(ScoresRange scoresRange, GamepadButtons button)
 {
     if (KeyBindings.ContainsKey(button))
     {
         KeyBindings[button] = scoresRange;
     }
     else
     {
         KeyBindings.Add(button, scoresRange);
     }
 }
Esempio n. 13
0
        public void GetThumbRadius(GamepadButtons buttonType, ref double radius)
        {
            if (buttonType == GamepadButtons.RightThumb)
            {
                radius = _rightThumbRadius;
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                radius = _leftThumbRadius;
            }
        }
Esempio n. 14
0
 public bool IsGamePadButtonPressed(GamepadButtons what)
 {
     if (Gamepad.Gamepads?.Count > 0)
     {
         var reading = Gamepad.Gamepads[0].GetCurrentReading();
         var result  = reading.Buttons.HasFlag(what);
         return(result);
     }
     else
     {
         return(true);
     }
 }
 protected void UpdateButtonState(GamepadButtons button, bool isDown)
 {
     if (isDown && !DownButtons.Contains(button))
     {
         PressedButtons.Add(button);
         DownButtons.Add(button);
     }
     else if (!isDown && DownButtons.Contains(button))
     {
         ReleasedButtons.Add(button);
         DownButtons.Remove(button);
     }
 }
Esempio n. 16
0
        public void GetThumbXY(GamepadButtons buttonType, ref double ThumbX, ref double ThumbY)
        {
            if (buttonType == GamepadButtons.RightThumb)
            {
                ThumbX = _rightThumbX;
                ThumbY = _rightThumbY;
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                ThumbX = _leftThumbX;
                ThumbY = _leftThumbY;
            }
        }
Esempio n. 17
0
        public static byte ToControlByte(this GamepadButtons buttons)
        {
            byte data = 0;

            data |= (byte)((((buttons & GamepadButtons.A) == GamepadButtons.A) ? 1 : 0) << 7);
            data |= (byte)((((buttons & GamepadButtons.B) == GamepadButtons.B) ? 1 : 0) << 6);
            data |= (byte)((((buttons & GamepadButtons.Select) == GamepadButtons.Select) ? 1 : 0) << 5);
            data |= (byte)((((buttons & GamepadButtons.Start) == GamepadButtons.Start) ? 1 : 0) << 4);
            data |= (byte)((((buttons & GamepadButtons.Up) == GamepadButtons.Up) ? 1 : 0) << 3);
            data |= (byte)((((buttons & GamepadButtons.Down) == GamepadButtons.Down) ? 1 : 0) << 2);
            data |= (byte)((((buttons & GamepadButtons.Left) == GamepadButtons.Left) ? 1 : 0) << 1);
            data |= (byte)((((buttons & GamepadButtons.Right) == GamepadButtons.Right) ? 1 : 0) << 0);

            return(data);
        }
        private static float ButtonsToAnalog(GamepadReading?reading, GamepadButtons positive, GamepadButtons negative, float magnitude = 1)
        {
            float output = 0;

            if (reading?.Buttons.HasFlag(positive) ?? false)
            {
                output += magnitude;
            }

            if (reading?.Buttons.HasFlag(negative) ?? false)
            {
                output -= magnitude;
            }

            return(output);
        }
Esempio n. 19
0
        public void SetThumbRadius(GamepadButtons buttonType, double ThumbX, double ThumbY)
        {
            if (buttonType == GamepadButtons.RightThumb)
            {
                _rightThumbRadius = Math.Sqrt(ThumbX * ThumbX + ThumbY * ThumbY);
                _rightThumbX      = ThumbX;
                _rightThumbY      = ThumbY;
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                _leftThumbRadius = Math.Sqrt(ThumbX * ThumbX + ThumbY * ThumbY);
                _leftThumbX      = ThumbX;
                _leftThumbY      = ThumbY;
            }
        }
Esempio n. 20
0
        public bool TryLoadButtonAssignment(GamepadButtons button, out VirtualKey assignment)
        {
            assignment = VirtualKey.None;
            var value = settings.Values[button.ToString()] as string;

            if (value == null)
            {
                return(false);
            }

            if (Enum.TryParse <VirtualKey>(value, out assignment))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 21
0
        private void GetThumbXY(GamepadButtons buttonType, int deviceID, ref double ThumbX, ref double ThumbY)
        {
            XInputState gpState;

            XInputMethods.GetState(deviceID, out gpState);
            XInputGamepad gp = gpState.Gamepad;

            if (buttonType == GamepadButtons.RightThumb)
            {
                ThumbX = (double)gp.RightThumbX;
                ThumbY = (double)gp.RightThumbY;
            }
            if (buttonType == GamepadButtons.LeftThumb)
            {
                ThumbX = (double)gp.LeftThumbX;
                ThumbY = (double)gp.LeftThumbY;
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Processes a button click.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <param name="gamepadButton">The gamepad button associated with the UI button.</param>
        private void ProcessButtonClick(Button button, GamepadButtons gamepadButton)
        {
            if (!this.assigning)
            {
                this.DisableButtonsExcept(button);
                this.SetAssignmentVariables(button, gamepadButton);
            }
            else
            {
                if (!this.deferringClear)
                {
                    UnassignButton(gamepadButton);
                }

                this.ClearAssignmentVariables();
                this.EnableButtons();
                this.deferringClear = false;
            }
        }
Esempio n. 23
0
    public static GamepadButtons?GetDirectionPressed(InputEvent inputEvent)
    {
        if (!IsDpadDevice(inputEvent))
        {
            return(null);
        }

        GamepadButtons directionPressed = GamepadButtons.None;

        // If the input event is a MotionEvent, check its hat axis values.
        if (inputEvent is MotionEvent)
        {
            // Use the hat axis value to find the D-pad direction
            MotionEvent motionEvent = (MotionEvent)inputEvent;

            float xaxis = motionEvent.GetAxisValue(Axis.HatX);
            float yaxis = motionEvent.GetAxisValue(Axis.HatY);

            // Check if the AXIS_HAT_X value is -1 or 1, and set the D-pad
            // LEFT and RIGHT direction accordingly.
            if (Math.Abs(xaxis - (-1.0f)) < Epsilon)
            {
                directionPressed = directionPressed | GamepadButtons.DPadLeft;
            }
            else if (Math.Abs(xaxis - 1.0f) < Epsilon)
            {
                directionPressed = directionPressed | GamepadButtons.DPadRight;
            }
            // Check if the AXIS_HAT_Y value is -1 or 1, and set the D-pad
            // UP and DOWN direction accordingly.
            if (Math.Abs(yaxis - (-1.0f)) < Epsilon)
            {
                directionPressed = directionPressed | GamepadButtons.DPadUp;
            }
            else if (Math.Abs(yaxis - 1.0f) < Epsilon)
            {
                directionPressed = directionPressed | GamepadButtons.DPadDown;
            }
        }
        return(directionPressed);
    }
Esempio n. 24
0
 private void DisplayControllerState(GamepadReading reading, GamepadButtons buttons)
 {
     LeftThumbstickState.Text   = "Left Stick: " + Math.Round(reading.LeftThumbstickX, 1) + ", " + Math.Round(reading.LeftThumbstickY, 1);
     RightThumbstickState.Text  = "Right Stick: " + Math.Round(reading.RightThumbstickX, 1) + ", " + Math.Round(reading.RightThumbstickY, 1);
     LeftTriggerState.Text      = "Left Trigger: " + Math.Round(reading.LeftTrigger, 1);
     RightTriggerState.Text     = "Right Trigger: " + Math.Round(reading.RightTrigger, 1);
     LeftBumperState.Text       = "Left Bumper: " + buttons.HasFlag(GamepadButtons.LeftShoulder);
     RightBumperState.Text      = "Right Bumper: " + buttons.HasFlag(GamepadButtons.RightShoulder);
     MenuState.Text             = "Menu: " + buttons.HasFlag(GamepadButtons.Menu).ToString();
     ViewState.Text             = "View: " + buttons.HasFlag(GamepadButtons.View).ToString();
     LeftThumbButtonState.Text  = "Left Stick Button: " + buttons.HasFlag(GamepadButtons.LeftThumbstick).ToString();
     RightThumbButtonState.Text = "Right Stick Button: " + buttons.HasFlag(GamepadButtons.RightThumbstick).ToString();
     DPadUpState.Text           = "D-Pad Up: " + buttons.HasFlag(GamepadButtons.DPadUp).ToString();
     DPadDownState.Text         = "D-Pad Down: " + buttons.HasFlag(GamepadButtons.DPadDown).ToString();
     DPadLeftState.Text         = "D-Pad Left: " + buttons.HasFlag(GamepadButtons.DPadLeft).ToString();
     DPadRightState.Text        = "D-Pad Right: " + buttons.HasFlag(GamepadButtons.DPadRight).ToString();
     AState.Text = "A: " + buttons.HasFlag(GamepadButtons.A).ToString();
     BState.Text = "B: " + buttons.HasFlag(GamepadButtons.B).ToString();
     XState.Text = "X: " + buttons.HasFlag(GamepadButtons.X).ToString();
     YState.Text = "Y: " + buttons.HasFlag(GamepadButtons.Y).ToString();
 }
        public bool isThumbPostionInsideRadius(GamepadButtons buttonType, double currentThumbX, double currentThumbY, double tol)
        {

            double radius = 0.0;

            radius = Math.Sqrt(currentThumbX * currentThumbX + currentThumbY * currentThumbY);

            if (buttonType == GamepadButtons.RightThumb)
            {
                if ((_rightThumbRadius <= radius + tol) && (_rightThumbRadius >= radius - tol))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            
            if (buttonType == GamepadButtons.LeftThumb)
            {
                if ((_leftThumbRadius <= radius + tol) && (_leftThumbRadius >= radius - tol))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return false;
        }
        /**
         * This updates the state of the device and triggers events
         * to any registered listeners.
         **/
        public void Update()
        {
            try
            {
                XInputState gpState;
                XInputMethods.GetState(deviceID, out gpState);
                XInputGamepad gp = gpState.Gamepad;
               // If previously disconnected, notify of connect
                if (!isConnected && OnConnect != null)
                {
                    isConnected = true;
                    OnConnect(this, new GamepadEventArgs(deviceID, GamepadState.Connected));
                }
 
                if (isConnected)
                {
                    // A Button
                    // Check to see if anything changed
                    if (!(lastAButtonState == gp.IsAButtonDown))
                    {
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.A, gp.IsAButtonDown);

                        if (gp.IsAButtonDown) // If button changed to press state
                        {
                            if (OnAButtonPress != null) OnAButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnAButtonRelease != null) OnAButtonRelease(this, btnEvt);
                        }

                        lastAButtonState = gp.IsAButtonDown;
                    }

                    // B Button
                    // Check to see if anything changed
                    if (!(lastBButtonState == gp.IsBButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.B, gp.IsBButtonDown);

                        if (gp.IsBButtonDown) // If button changed to press state
                        {
                            if (OnBButtonPress != null) OnBButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnBButtonRelease != null) OnBButtonRelease(this, btnEvt);
                        }

                        lastBButtonState = gp.IsBButtonDown;
                    }

                    // X Button
                    // Check to see if anything changed
                    if (!(lastXButtonState == gp.IsXButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.X, gp.IsXButtonDown);

                        if (gp.IsXButtonDown) // If button changed to press state
                        {
                            if (OnXButtonPress != null) OnXButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnXButtonRelease != null) OnXButtonRelease(this, btnEvt);
                        }

                        lastXButtonState = gp.IsXButtonDown;
                    }

                    // Y Button
                    // Check to see if anything changed
                    if (!(lastYButtonState == gp.IsYButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.Y, gp.IsYButtonDown);

                        if (gp.IsYButtonDown) // If button changed to press state
                        {
                            if (OnYButtonPress != null) OnYButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnYButtonRelease != null) OnYButtonRelease(this, btnEvt);
                        }

                        lastYButtonState = gp.IsYButtonDown;
                    }

                    // Back Button
                    // Check to see if anything changed
                    if (!(lastBackButtonState == gp.IsBackButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.Back, gp.IsBackButtonDown);

                        if (gp.IsBackButtonDown) // If button changed to press state
                        {
                            if (OnBackButtonPress != null) OnBackButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnBackButtonRelease != null) OnBackButtonRelease(this, btnEvt);
                        }

                        lastBackButtonState = gp.IsBackButtonDown;
                    }

                    // Start Button
                    // Check to see if anything changed
                    if (!(lastStartButtonState == gp.IsStartButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.Start, gp.IsStartButtonDown);

                        if (gp.IsStartButtonDown) // If button changed to press state
                        {
                            if (OnStartButtonPress != null) OnStartButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnStartButtonRelease != null) OnStartButtonRelease(this, btnEvt);
                        }

                        lastStartButtonState = gp.IsStartButtonDown;
                    }

                    // Left Thumb Button
                    // Check to see if anything changed
                    if (!(lastLeftThumbButtonState == gp.IsLeftThumbButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.LeftThumb, gp.IsLeftThumbButtonDown);

                        if (gp.IsLeftThumbButtonDown) // If button changed to press state
                        {
                            if (OnLeftThumbButtonPress != null) OnLeftThumbButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnLeftThumbButtonRelease != null) OnLeftThumbButtonRelease(this, btnEvt);
                        }

                        lastLeftThumbButtonState = gp.IsLeftThumbButtonDown;
                    }

                    // Right Thumb Button
                    // Check to see if anything changed
                    if (!(lastRightThumbButtonState == gp.IsRightThumbButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.RightThumb, gp.IsRightThumbButtonDown);

                        if (gp.IsRightThumbButtonDown) // If button changed to press state
                        {
                            if (OnRightThumbButtonPress != null) OnRightThumbButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnRightThumbButtonRelease != null) OnRightThumbButtonRelease(this, btnEvt);
                        }

                        lastRightThumbButtonState = gp.IsRightThumbButtonDown;
                    }

                    // Left Shoulder Button
                    // Check to see if anything changed
                    if (!(lastLeftShoulderButtonState == gp.IsLeftShoulderButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.LeftShoulder, gp.IsLeftShoulderButtonDown);

                        if (gp.IsLeftShoulderButtonDown) // If button changed to press state
                        {
                            if (OnLeftShoulderButtonPress != null) OnLeftShoulderButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnLeftShoulderButtonRelease != null) OnLeftShoulderButtonRelease(this, btnEvt);
                        }

                        lastLeftShoulderButtonState = gp.IsLeftShoulderButtonDown;
                    }

                    // Right Shoulder Button
                    // Check to see if anything changed
                    if (!(lastRightShoulderButtonState == gp.IsRightShoulderButtonDown))
                    {
                        // Something has changed, lets dispatch events
                        GamepadButtonEventArgs btnEvt = new GamepadButtonEventArgs(deviceID, GamepadButtons.RightShoulder, gp.IsRightShoulderButtonDown);

                        if (gp.IsRightShoulderButtonDown) // If button changed to press state
                        {
                            if (OnRightShoulderButtonPress != null) OnRightShoulderButtonPress(this, btnEvt);
                        }
                        else // If button changed to release state
                        {
                            if (OnRightShoulderButtonRelease != null) OnRightShoulderButtonRelease(this, btnEvt);
                        }

                        lastRightShoulderButtonState = gp.IsRightShoulderButtonDown;
                    }

                    // DPad
                    // Check to see if DPad state has changed.
                    GamepadButtons tmpButtons = (GamepadButtons)gp.Buttons;
                    GamepadButtons dpNewState = (GamepadButtons)((int)tmpButtons % 0x10); // Remove other button states
                    if (dpNewState != _lastDPadState) // A change has occured
                    {
                        GamepadDPadEventArgs padEvt = new GamepadDPadEventArgs(deviceID, dpNewState);

                        if (dpNewState == 0) // DPad has been released
                        {
                            if (OnDPadRelease != null) 
                                if(!(_RightThumbMoving || _LeftThumbMoving))
                            {
                                OnDPadRelease(this, padEvt);
                            }
                        }
                        else if (_lastDPadState == 0) // DPad has been pressed
                        {
                            if (OnDPadPress != null)
                            {
                                if (!(_RightThumbMoving || _LeftThumbMoving))
                                {
                                    OnDPadPress(this, padEvt);
                                }
                            }
                        }

                        if (OnDPadChange != null) OnDPadChange(this, padEvt);

                        _lastDPadState = dpNewState;
                    }
                    else if ((_lastDPadState == GamepadButtons.DPadUp) || (_lastDPadState == GamepadButtons.DPadDown)) // If the button is pressed
                    {
                        if (!(_RightThumbMoving || _LeftThumbMoving))
                        {
                            GamepadDPadEventArgs padEvt = new GamepadDPadEventArgs(deviceID, dpNewState);
                            OnDPadPress(this, padEvt);
                        }

                    }

                    // Left Trigger
                    // Check to see if left trigger has changed.
                    if (lastLeftTrigger != gp.LeftTrigger) // A change has occured
                    {
                        GamepadTriggerEventArgs trigEvt = new GamepadTriggerEventArgs(deviceID, GamepadTriggers.Left, gp.LeftTrigger);

                        if (!leftTriggerPressed) // Trigger was pressed
                        {
                            leftTriggerPressed = true;
                            if (OnLeftTriggerPress != null) OnLeftTriggerPress(this, trigEvt);
                        }
                        else if (gp.LeftTrigger == 0) // Trigger was released
                        {
                            if (OnLeftTriggerRelease != null) OnLeftTriggerRelease(this, trigEvt);
                            leftTriggerPressed = false;
                        }

                        if (OnLeftTriggerChange != null) OnLeftTriggerChange(this, trigEvt);

                        lastLeftTrigger = gp.LeftTrigger;
                    }

                    // Right Trigger
                    // Check to see if right trigger has changed.
                    if (lastRightTrigger != gp.RightTrigger) // A change has occured
                    {
                        GamepadTriggerEventArgs trigEvt = new GamepadTriggerEventArgs(deviceID, GamepadTriggers.Right, gp.RightTrigger);

                        if (!rightTriggerPressed) // Trigger was pressed
                        {
                            rightTriggerPressed = true;
                            if (OnRightTriggerPress != null) OnRightTriggerPress(this, trigEvt);
                        }
                        else if (gp.RightTrigger == 0) // Trigger was released
                        {
                            if (OnRightTriggerRelease != null) OnRightTriggerRelease(this, trigEvt);
                            rightTriggerPressed = false;
                        }

                        if (OnRightTriggerChange != null) OnRightTriggerChange(this, trigEvt);

                        lastRightTrigger = gp.RightTrigger;
                    }

                    // Left Thumb Joystick
                    GamepadThumbEventArgs joyEvt = new GamepadThumbEventArgs(deviceID, GamepadThumbs.Left, gp.LeftThumbX, gp.LeftThumbY, gp.IsLeftThumbButtonDown);
                    if (!isThumbPostionInsideRadius(GamepadButtons.LeftThumb, gp.LeftThumbX, gp.LeftThumbY, 8000.0))
                    {
                        if (OnLeftThumbUpdate != null)
                        {
                            if (_RightThumbMoving)
                            {
                                _Move3Axis = true;
                                OnLeftThumbUpdate(this, joyEvt);
                                _LeftThumbMoving = true;
                            }

                            else
                            {
                                _Move3Axis = false;
                                OnLeftThumbUpdate(this, joyEvt);
                                _LeftThumbMoving = true;

                            }
                        
                        }

                    }
                    else
                    {
                        if (IsNoButtonHeldDown(gp))
                        {
                            if (OnThumbBackInsideRadius != null) OnThumbBackInsideRadius(this, joyEvt);
                            _LeftThumbMoving = false;
                        }
                    }

                    // Right Thumb Joystick
                    GamepadThumbEventArgs joyEvt1 = new GamepadThumbEventArgs(deviceID, GamepadThumbs.Right, gp.RightThumbX, gp.RightThumbY, gp.IsRightThumbButtonDown);
                    if (!isThumbPostionInsideRadius(GamepadButtons.RightThumb, gp.RightThumbX, gp.RightThumbY, 8000.0))
                    {
                        if (OnRightThumbUpdate != null)
                        {
                            if (!gp.IsDPadUpButtonDown && !gp.IsDPadDownButtonDown && !_LeftThumbMoving)
                            {
                                _Move3Axis = false;
                                OnRightThumbUpdate(this, joyEvt1);
                                _RightThumbMoving = true;
                            }
                            else
                            {

                                _Move3Axis = true;
                                OnRightThumbUpdate(this, joyEvt1);
                                _RightThumbMoving = true;

                            }
                        }
                    }
                    else
                    {
                        if ( (IsNoButtonHeldDown(gp) && !_LeftThumbMoving) )
                        {
                            if (OnThumbBackInsideRadius != null) OnThumbBackInsideRadius(this, joyEvt1);
                            _RightThumbMoving = false;
                        }
                    }
                    // Update complete
                }
            }
            catch (Win32Exception e)
            {
                if (e.NativeErrorCode == 1167) // This is a disconnect error
                {
                    if (OnDisconnect != null) OnDisconnect(this, new GamepadEventArgs(deviceID, GamepadState.Disconnected));
                    isConnected = false;
                }
                else
                {
                    throw e; // Unknown error, rethrow
                }
            }
        }
        public void GetThumbRadius(GamepadButtons buttonType, ref double radius)
        {

            if (buttonType == GamepadButtons.RightThumb)
            {
                radius = _rightThumbRadius;
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                radius = _leftThumbRadius;
            }

        }
        public void GetThumbXY(GamepadButtons buttonType, ref double ThumbX, ref double ThumbY)
        {

            if (buttonType == GamepadButtons.RightThumb)
            {
                ThumbX = _rightThumbX;
                ThumbY = _rightThumbY;
            }

            if (buttonType == GamepadButtons.LeftThumb)
            {
                ThumbX = _leftThumbX;
                ThumbY = _leftThumbY;
            }

        }
Esempio n. 29
0
 /// <summary>
 /// Clears assignment variables after an assignment or canceled assignment.
 /// </summary>
 private void ClearAssignmentVariables()
 {
     this.assigning             = false;
     this.assignedGamepadButton = GamepadButtons.None;
     this.assignedButton        = null;
 }
        public void SetThumbRadius(GamepadButtons buttonType, double ThumbX, double ThumbY)
        {

            if (buttonType == GamepadButtons.RightThumb)
            {
                _rightThumbRadius = Math.Sqrt(ThumbX * ThumbX + ThumbY * ThumbY);
                _rightThumbX = ThumbX;
                _rightThumbY = ThumbY;
            }
            
            if (buttonType == GamepadButtons.LeftThumb)
            {
                _leftThumbRadius = Math.Sqrt(ThumbX * ThumbX + ThumbY * ThumbY);
                _leftThumbX = ThumbX;
                _leftThumbY = ThumbY;
            }

        }
Esempio n. 31
0
 /// <summary>
 /// Gets whether <paramref name="button"/> has been pressed.
 ///
 /// Only true on first frame of the press.
 /// If ImGuiConfigFlags.NavEnableGamepad is set, this is unreliable.
 /// </summary>
 /// <param name="button">The button to check for.</param>
 /// <returns>1 if pressed, 0 otherwise.</returns>
 public float Pressed(GamepadButtons button) => (this.ButtonsPressed & (ushort)button) > 0 ? 1 : 0;
Esempio n. 32
0
 /// <summary>
 /// A value indicating whether the specified button is pressed.
 /// </summary>
 /// <param name="button">The GamepadButton.</param>
 /// <returns>True if currently pressed.</returns>
 public bool IsPressed(GamepadButtons button)
 {
     return _states[button];
 }
Esempio n. 33
0
 public ButtonState this[GamepadButtons gamePadButton]
 {
     get { return _gamepadButtonStates[(int)gamePadButton - 1]; }
 }
Esempio n. 34
0
        /// <summary>
        /// Processes a button click.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <param name="gamepadButton">The gamepad button associated with the UI button.</param>
        private void ProcessButtonClick(Button button, GamepadButtons gamepadButton)
        {
            if (!this.assigning)
            {
                this.DisableButtonsExcept(button);
                this.SetAssignmentVariables(button, gamepadButton);
            }
            else
            {
                if (!this.deferringClear)
                {
                    this.assignedButtons.Remove(gamepadButton);
                    this.assignedButton.Content = "Unassigned";
                }

                this.ClearAssignmentVariables();
                this.EnableButtons();
                this.deferringClear = false;
            }
        }
Esempio n. 35
0
 /// <summary>
 /// Clears assignment variables after an assignment or canceled assignment.
 /// </summary>
 private void ClearAssignmentVariables()
 {
     this.assigning = false;
     this.assignedGamepadButton = GamepadButtons.None;
     this.assignedButton = null;
 }
Esempio n. 36
0
 /// <summary>
 /// Sets the assignment variables to begin button assignment.
 /// </summary>
 /// <param name="button">The button.</param>
 /// <param name="gamepadButton">The gamepad button.</param>
 private void SetAssignmentVariables(Button button, GamepadButtons gamepadButton)
 {
     this.assigning = true;
     this.assignedGamepadButton = gamepadButton;
     this.assignedButton = button;
 }
Esempio n. 37
0
        private GamePadButtonStatus ConvertButtonsFromMsft(GamepadButtons buttonsenum)
        {
            var gamepadbuttons = new GamePadButtonStatus();

            if (buttonsenum.HasFlag((GamepadButtons)0))
                gamepadbuttons.None = true;
            if (buttonsenum.HasFlag((GamepadButtons)1))
                gamepadbuttons.Menu = true;
            if (buttonsenum.HasFlag((GamepadButtons)2))
                gamepadbuttons.View = true;
            if (buttonsenum.HasFlag((GamepadButtons)4))
                gamepadbuttons.A = true;
            if (buttonsenum.HasFlag((GamepadButtons)8))
                gamepadbuttons.B = true;
            if (buttonsenum.HasFlag((GamepadButtons)16))
                gamepadbuttons.X = true;
            if (buttonsenum.HasFlag((GamepadButtons)32))
                gamepadbuttons.Y = true;
            if (buttonsenum.HasFlag((GamepadButtons)64))
                gamepadbuttons.Up = true;
            if (buttonsenum.HasFlag((GamepadButtons)128))
                gamepadbuttons.Down = true;
            if (buttonsenum.HasFlag((GamepadButtons)256))
                gamepadbuttons.Left = true;
            if (buttonsenum.HasFlag((GamepadButtons)512))
                gamepadbuttons.Right = true;
            if (buttonsenum.HasFlag((GamepadButtons)1024))
                gamepadbuttons.LeftShoulder = true;
            if (buttonsenum.HasFlag((GamepadButtons)2048))
                gamepadbuttons.RightShoulder = true;
            if (buttonsenum.HasFlag((GamepadButtons)4096))
                gamepadbuttons.LeftThumbstick = true;
            if (buttonsenum.HasFlag((GamepadButtons)8192))
                gamepadbuttons.RightThumbstick = true;

            return gamepadbuttons;
        }
 public GamepadButtonEventArgs(int DeviceID, GamepadButtons Button, bool IsPressed)
 {
     this.DeviceID = DeviceID;
     this.Button = Button;
     this.IsPressed = IsPressed;
 }
Esempio n. 39
0
 /// <summary>
 /// Gets whether <paramref name="button"/> has been released.
 ///
 /// Only true the frame after release.
 /// If ImGuiConfigFlags.NavEnableGamepad is set, this is unreliable.
 /// </summary>
 /// <param name="button">The button to check for.</param>
 /// <returns>1 if released, 0 otherwise.</returns>
 public float Released(GamepadButtons button) => (this.ButtonsReleased & (ushort)button) > 0 ? 1 : 0;
 public GamepadDPadEventArgs(int DeviceID, GamepadButtons Buttons)
 {
     this.DeviceID = DeviceID;
     this.Buttons = Buttons;
 }
        private void GetThumbXY(GamepadButtons buttonType, int deviceID, ref double ThumbX, ref double ThumbY)
        {

            XInputState gpState;
            XInputMethods.GetState(deviceID, out gpState);
            XInputGamepad gp = gpState.Gamepad;

            if (buttonType == GamepadButtons.RightThumb)
            {
                ThumbX = (double)gp.RightThumbX;
                ThumbY = (double)gp.RightThumbY;
            }
            if (buttonType == GamepadButtons.LeftThumb)
            {
                ThumbX = (double)gp.LeftThumbX;
                ThumbY = (double)gp.LeftThumbY;
            }

        }
Esempio n. 42
0
 /// <summary>
 /// Gets whether <paramref name="button"/> is being pressed.
 ///
 /// True in intervals if button is held down.
 /// If ImGuiConfigFlags.NavEnableGamepad is set, this is unreliable.
 /// </summary>
 /// <param name="button">The button to check for.</param>
 /// <returns>1 if still pressed during interval, 0 otherwise or in between intervals.</returns>
 public float Repeat(GamepadButtons button) => (this.ButtonsRepeat & (ushort)button) > 0 ? 1 : 0;
Esempio n. 43
0
		/// <summary>
		/// Returns whether a specified key is currently being pressed. 
		/// </summary>
		/// <param name="button"></param>
		/// <returns></returns>
		public bool IsButtonPressed(GamepadButtons button)
		{
			return gamePad.IsKeyPressed( (Fusion.Drivers.Input.GamepadButtons)button );
		}
Esempio n. 44
0
 /// <summary>
 /// Gets the raw state of <paramref name="button"/>.
 ///
 /// Is set the entire time a button is pressed down.
 /// </summary>
 /// <param name="button">The button to check for.</param>
 /// <returns>1 the whole time button is pressed, 0 otherwise.</returns>
 public float Raw(GamepadButtons button) => (this.ButtonsRaw & (ushort)button) > 0 ? 1 : 0;
Esempio n. 45
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="button"></param>
		/// <returns></returns>
		public bool IsKeyPressed(GamepadButtons button)
		{
			if (((int) state.Gamepad.Buttons & (int) button) != 0) return true;

			return false;
		}
Esempio n. 46
0
 /// <summary>
 /// Sets the assignment variables to begin button assignment.
 /// </summary>
 /// <param name="button">The button.</param>
 /// <param name="gamepadButton">The gamepad button.</param>
 private void SetAssignmentVariables(Button button, GamepadButtons gamepadButton)
 {
     this.assigning             = true;
     this.assignedGamepadButton = gamepadButton;
     this.assignedButton        = button;
 }
Esempio n. 47
0
File: Hero.cs Progetto: mokujin/DN
 private void g_Gamepad_OnButtonUp(object sender, GamepadButtons e)
 {
     if (e.HasFlag(GamepadButtons.A))
     {
         StopJump();
     }
     else if (e.HasFlag(GamepadButtons.X))
     {
         if (InHandItem != null)
             InHandItem.FinishAction();
     }
 }