Share via


GamePad.GetState Method (PlayerIndex, GamePadDeadZone)

Gets the current state of an Xbox 360 Controller, using a specified dead zone on analog stick positions.

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

Syntax

public static GamePadState GetState (
         PlayerIndex playerIndex,
         GamePadDeadZone deadZoneMode
)

Parameters

  • playerIndex
    Player index for the controller you want to query.
  • deadZoneMode
    Enumerated value that specifies what dead zone type to use.

Return Value

The current state of the controller.

Exceptions

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

Remarks

When calling 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. The controller will also not be able to receive new vibration settings.

The deadZoneMode parameter specifies the type of dead-zone processing to apply to the analog sticks on the controller. By applying a dead zone, controller inputs will report values near the center and edges of their ranges more accurately. If you wish to do your own dead-zone processing, use GamePadDeadZone.None.

See Also

Tasks

How to: Detect Whether a Controller Button Is Pressed
How to: Detect Whether a Controller Is Disconnected

Concepts

Input Overview

Reference

GamePad Class
GamePad Members
Microsoft.Xna.Framework.Input Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista