GamePad.GetState Method (PlayerIndex)

Gets the current state of a game pad controller.

Namespace: Microsoft.Xna.Framework.Input
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

public static GamePadState GetState (
         PlayerIndex playerIndex


Type: PlayerIndex
Player index for the controller you want to query.

Return Value

The current state of the controller.

Exception typeCondition
InvalidOperationException An unknown error has occurred. Verify that the correct playerIndex is being requested.

Bb197230.bp(en-us,XNAGameStudio.41).gifBest Practice
  • On the first menu presented by the game, consider asking the player to sign in by pressing A or Start. This enables the game to detect the correct controller in use for each player in the game.

  • When processing player input, you can examine SignedInGamer.GameDefaults to determine a player's preferences for how the Xbox 360 controller is used to send input to the game.

When you call GetState, check the returned structure's IsConnected property value. If the controller has been disconnected, this value will be false. When a controller is disconnected, values for its state will not be valid. Also, the controller will not receive any new vibration settings.

This method uses the GamePadDeadZone.IndependentAxes dead zone to smooth the values of the analog sticks. To specify a different dead zone type, or to specify no-dead-zone processing, pass a GamePadDeadZone value to this method.

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone

Community Additions