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); }
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); } } }
/// <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); } }
private bool IsButtonJustPressed(GamepadButtons selection) { bool newSelectionPressed = (selection == (_currentReading.Buttons & selection)); bool oldSelectionPressed = (selection == (_previousReading.Buttons & selection)); return(newSelectionPressed && !oldSelectionPressed); }
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); }
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; } }
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); }
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); } }
public GamepadButtonDown(TimeSpan buttonDownTime, GamepadButtons gamepadButtonOne, GamepadButtons gamepadButtonTwo) { _buttonDownTime = buttonDownTime; _gamepadButtonOne = gamepadButtonOne; _gamepadButtonTwo = gamepadButtonTwo; }
/// <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); }
public void PerformAction(GamepadButtons button) { MainActionTypes?actionType = _actionsProvider.GetAction(button); if (actionType.HasValue) { _actionHandler.PerformAction(actionType.Value); } }
public void AddScoresKeyBinding(ScoresRange scoresRange, GamepadButtons button) { if (KeyBindings.ContainsKey(button)) { KeyBindings[button] = scoresRange; } else { KeyBindings.Add(button, scoresRange); } }
public void GetThumbRadius(GamepadButtons buttonType, ref double radius) { if (buttonType == GamepadButtons.RightThumb) { radius = _rightThumbRadius; } if (buttonType == GamepadButtons.LeftThumb) { radius = _leftThumbRadius; } }
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); } }
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; } }
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); }
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; } }
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); }
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; } }
/// <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; } }
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); }
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 } } }
/// <summary> /// Clears assignment variables after an assignment or canceled assignment. /// </summary> private void ClearAssignmentVariables() { this.assigning = false; this.assignedGamepadButton = GamepadButtons.None; this.assignedButton = null; }
/// <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;
/// <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]; }
public ButtonState this[GamepadButtons gamePadButton] { get { return _gamepadButtonStates[(int)gamePadButton - 1]; } }
/// <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; } }
/// <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; }
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; }
/// <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; }
/// <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;
/// <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 ); }
/// <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;
/// <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; }
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(); } }