internal void Update() { GamePadState state = XnaGamePad.GetState(_playerIndex); foreach (var en in _keys) { bool isPressed = state.IsButtonDown(en); bool wasPressed = _states[en] != GamePadButtonState.Released; if (isPressed) { if (wasPressed) { _states[en] = GamePadButtonState.Hold; } else { _states[en] = GamePadButtonState.Pressed; } } else { _states[en] = GamePadButtonState.Released; } } }
public GamePadType getGamePadType() { string displayName = GamePad.GetCapabilities(_playerIndex).DisplayName; if (displayName == null) { displayName = ""; } else { displayName = displayName.ToLower(); } for (int i = 0; i < PS4GamePad.ID.Length; i++) { if (displayName.Contains(PS4GamePad.ID[i])) { return(GamePadType.PS4); } } for (int i = 0; i < XboxGamePad.ID.Length; i++) { if (displayName.Contains(XboxGamePad.ID[i])) { return(GamePadType.XBOX); } } return(GamePadType.UNKNOWN); }
private GamePadStatus getStatus() { var state = GamePad.GetState(_playerIndex); var status = new GamePadStatus(); status.isConnected = state.IsConnected; status.buttons = new bool[buttonCodes.Length]; for (var i = 0; i < buttonCodes.Length; i++) { status.buttons[i] = state.IsButtonDown((Buttons)buttonCodes[i]); } status.axes = new [] { state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y, state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y, state.Triggers.Left, state.Triggers.Right }; status.povs = new[] { getPov(0) }; status.accelerometers = new Vector3[0]; return(status); }
public float getAxis(int axisCode) { var state = GamePad.GetState(_playerIndex); switch ((AxisCodes)axisCode) { case AxisCodes.LeftThumbstickX: return(state.ThumbSticks.Left.X); case AxisCodes.LeftThumbstickY: return(state.ThumbSticks.Left.Y); case AxisCodes.RightThumbstickX: return(state.ThumbSticks.Right.X); case AxisCodes.RightThumbstickY: return(state.ThumbSticks.Right.Y); case AxisCodes.LeftTrigger: return(state.Triggers.Left); case AxisCodes.RightTrigger: return(state.Triggers.Right); default: return(0); } }
//=========== UPDATING =========== #region Updating /** <summary> Called every step to update the button states. </summary> */ public static void Update(GameTime gameTime) { for (int i = 0; i < 4; i++) { XnaPlayer player = (XnaPlayer)i; buttons[i, (int)Buttons.A].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.A)); buttons[i, (int)Buttons.B].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.B)); buttons[i, (int)Buttons.X].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.X)); buttons[i, (int)Buttons.Y].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Y)); buttons[i, (int)Buttons.Start].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Start)); buttons[i, (int)Buttons.Back].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Back)); buttons[i, (int)Buttons.Home].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.BigButton)); buttons[i, (int)Buttons.LeftShoulder].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.LeftShoulder)); buttons[i, (int)Buttons.RightShoulder].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.RightShoulder)); buttons[i, (int)Buttons.LeftStickButton].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.LeftStick)); buttons[i, (int)Buttons.RightStickButton].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.RightStick)); Vector2F dPad = Vector2F.Zero; if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadRight)) { dPad.X = 1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadDown)) { dPad.Y = 1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadLeft)) { dPad.X = -1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadUp)) { dPad.Y = -1; } if (dPad.X != 0.0f && dPad.Y != 0.0f) { dPad.X /= GMath.Sqrt(2.0f); dPad.Y /= GMath.Sqrt(2.0f); } sticks[i, (int)Buttons.DPad].Update(1, dPad); Vector2F stick = Vector2F.Zero; stick = XnaGamePad.GetState(player).ThumbSticks.Left; stick.Y *= -1; sticks[i, (int)Buttons.LeftStick].Update(1, stick); stick = XnaGamePad.GetState(player).ThumbSticks.Right; stick.Y *= -1; sticks[i, (int)Buttons.RightStick].Update(1, stick); float trigger = XnaGamePad.GetState(player).Triggers.Left; triggers[i, (int)Buttons.LeftTrigger].Update(1, trigger); trigger = XnaGamePad.GetState(player).Triggers.Right; triggers[i, (int)Buttons.RightTrigger].Update(1, trigger); } }
public PovState getPov(int povCode) { if (povCode != 0) { throw new NotSupportedException(); } var state = GamePad.GetState(povCode).DPad; PovState povState = PovState.CENTER; if (state.Down == ButtonState.Pressed) { povState = PovState.SOUTH; } if (state.Up == ButtonState.Pressed) { povState = PovState.NORTH; } if (state.Left == ButtonState.Pressed) { if (povState == PovState.NORTH) { povState = PovState.NORTH_WEST; } else if (povState == PovState.SOUTH) { povState = PovState.SOUTH_WEST; } else { povState = PovState.WEST; } } if (state.Right == ButtonState.Pressed) { if (povState == PovState.NORTH) { povState = PovState.NORTH_EAST; } else if (povState == PovState.SOUTH) { povState = PovState.SOUTH_EAST; } else { povState = PovState.EAST; } } return(povState); }
public GamePadType getGamePadType() { switch (GamePad.GetCapabilities(_playerIndex).DisplayName) { case "X360 Controller": return(GamePadType.XBOX_360); default: return(GamePadType.UNKNOWN); } }
/// <summary>Updates the state of the input device</summary> /// <remarks> /// <para> /// If this method is called with no snapshots in the queue, it will take /// an immediate snapshot and make it the current state. This way, you /// can use the input devices without caring for the snapshot system if /// you wish. /// </para> /// <para> /// If this method is called while one or more snapshots are waiting in /// the queue, this method takes the next snapshot from the queue and makes /// it the current state. /// </para> /// </remarks> public override void Update() { GamePadState previous = this.current; if (this.states.Count == 0) { this.current = MsGamePad.GetState(this.playerIndex); } else { this.current = this.states.Dequeue(); } GenerateEvents(ref previous, ref this.current); }
public string getModelInfo() { return(GamePad.GetCapabilities(_playerIndex).DisplayName); }
public void stopVibration() { _isVibrating = false; _vibrationStrength = 0; GamePad.SetVibration(_playerIndex, 0, 0); }
public bool isButtonUp(int buttonCode) { return(GamePad.GetState(_playerIndex).IsButtonUp((Buttons)buttonCode)); }
public bool isVibrateSupported() { var capabilities = GamePad.GetCapabilities(_playerIndex); return(capabilities.HasRightVibrationMotor || capabilities.HasLeftVibrationMotor); }
public void startVibration(float strength) { _isVibrating = true; _vibrationStrength = strength; GamePad.SetVibration(_playerIndex, strength, strength); }
/// <summary>Takes a snapshot of the current state of the input device</summary> /// <remarks> /// This snapshot will be queued until the user calls the Update() method, /// where the next polled snapshot will be taken from the queue and provided /// to the user. /// </remarks> public override void TakeSnapshot() { this.states.Enqueue(MsGamePad.GetState(this.playerIndex)); }
public bool isConnected() { return(GamePad.GetState(_playerIndex).IsConnected); }
internal static GamePad GetGamePad(InputDevice device) { if (device == null || (device.Sources & InputSourceType.Gamepad) != InputSourceType.Gamepad) return null; // The recommended way to map devices to players numbers is to use OuyaController.GetPlayerNumByDeviceId(), // however as of ODK 0.0.6 there is a bug where disconnected and reconnected controllers get mapped // to new player numbers. Also, the player number returned does not match the LED on the controller. // Once this is fixed, we could consider using OuyaController.GetPlayerNumByDeviceId() // http://forums.ouya.tv/discussion/819/getplayernumbydeviceid-can-return-1-after-controllers-disconnect-and-reconnect int firstDisconnectedPadId = -1; for (int i = 0; i < GamePads.Length; i++) { var pad = GamePads[i]; if (pad != null && pad._isConnected && pad._deviceId == device.Id) { return pad; } else if (pad != null && !pad._isConnected && pad._descriptor == device.Descriptor) { Debug.WriteLine("Found previous controller [" + i + "] " + device.Name); pad._deviceId = device.Id; pad._isConnected = true; return pad; } else if (pad == null) { Debug.WriteLine("Found new controller [" + i + "] " + device.Name); pad = new GamePad(device); GamePads[i] = pad; return pad; } else if (!pad._isConnected && firstDisconnectedPadId < 0) { firstDisconnectedPadId = i; } } // If we get here, we failed to find a game pad or an empty slot to create one. // If we're holding onto a disconnected pad, overwrite it with this one if (firstDisconnectedPadId >= 0) { Debug.WriteLine("Found new controller in place of disconnected controller [" + firstDisconnectedPadId + "] " + device.Name); var pad = new GamePad(device); GamePads[firstDisconnectedPadId] = pad; return pad; } // All pad slots are taken so ignore further devices. return null; }
private void EventOnKeyUp(object sender, GamePad.KeyEventArgs keyEventArgs) { //m_debugText = string.Format("Detected Key: {0}", keyEventArgs.KeyCode); if (keyEventArgs.KeyCode == 82) { m_focusManager.SelectedButton = BtnPause; OnClick(null, new FocusManager.ClickEventArgs() {Button = BtnPause}); } }
public string getInstanceId() { return(GamePad.GetCapabilities(_playerIndex).DisplayName + "#" + _playerIndex); }
private GamePadState GetState() => MonogameGamePad.GetState(PlayerIndex.One);
private void UpdateGamePadState(PlayerIndex playerIndex) { _gamePads[(int)playerIndex] = _gamePads[(int)playerIndex].Next(GP.GetState(playerIndex)); }
internal override GamePadState GetState() { return(XnaGamePad.GetState(playerIndex)); }
internal static GamePad GetGamePad(InputDevice device) { if ((device.Sources & InputSourceType.Gamepad) != InputSourceType.Gamepad) return null; for (int i = 0; i < GamePads.Length; i++) { if (GamePads[i] == null) //Have looked at all the gamepads, must be a new one { Console.WriteLine("Found new controller [" + i + "] " + device.Name); GamePads[i] = new GamePad(device); return GamePads[i]; } if (GamePads[i]._deviceId == device.Id) { return GamePads[i]; } } return null; }
private static void UpdateGamePadState(PlayerIndex playerIndex) { GamePads[(int)playerIndex] = GamePads[(int)playerIndex].Next(GP.GetState(playerIndex)); }
internal override bool GetState() { return(XnaGamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)); }