C# Class ScreenManagement.InputState

Helper for reading input from keyboard and gamepad. This class tracks both the current and previous state of both input devices, and implements query methods for high level input actions such as "move up through the menu" or "pause the game".
ファイルを表示 Open project: giladgray/XNA-ScreenManager Class Usage Examples

Public Properties

Property Type Description
CurrentGamePadStates Microsoft.Xna.Framework.Input.GamePadState[]
CurrentKeyboardStates Microsoft.Xna.Framework.Input.KeyboardState[]
CurrentMousePosition Microsoft.Xna.Framework.Vector2
CurrentMouseState Microsoft.Xna.Framework.Input.MouseState
GamePadWasConnected bool[]
LastGamePadStates Microsoft.Xna.Framework.Input.GamePadState[]
LastKeyboardStates Microsoft.Xna.Framework.Input.KeyboardState[]
LastMouseState Microsoft.Xna.Framework.Input.MouseState

Public Methods

Method Description
InputState ( ) : Microsoft.Xna.Framework

Constructs a new input state.

IsMenuCancel ( PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool

Checks for a "menu cancel" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When the action is detected, the output playerIndex reports which player pressed it.

IsMenuDown ( PlayerIndex controllingPlayer ) : bool

Checks for a "menu down" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.

IsMenuLeft ( PlayerIndex controllingPlayer ) : bool

Checks for a "menu left" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.

IsMenuRight ( PlayerIndex controllingPlayer ) : bool

Checks for a "menu right" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.

IsMenuSelect ( PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool

Checks for a "menu select" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When the action is detected, the output playerIndex reports which player pressed it.

IsMenuUp ( PlayerIndex controllingPlayer ) : bool

Checks for a "menu up" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.

IsMouseMoved ( ) : bool

Helper for checking if the position of the mouse has changed during this update.

IsNewButtonPress ( Buttons button ) : bool

Helper for checking if a button was newly pressed during this update. This method is designed for use in one-player games and only checks the gamepad for player one.

IsNewButtonPress ( Buttons button, PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool

Helper for checking if a button was newly pressed during this update. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When a button press is detected, the output playerIndex reports which player pressed it.

IsNewKeyPress ( Keys key ) : bool

Helper for checking if a key was newly pressed during this update. This method is designed for use in PC games where there is only one keyboard.

IsNewKeyPress ( Keys key, PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool

Helper for checking if a key was newly pressed during this update. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When a keypress is detected, the output playerIndex reports which player pressed it.

IsNewMouseButtonPress ( MouseButtons button ) : bool

Helper for checking if a mouse button was newly pressed during this update. No controlling player parameter is required because there is only one mouse.

IsPauseGame ( PlayerIndex controllingPlayer ) : bool

Checks for a "pause the game" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.

Update ( ) : void

Reads the latest state of the keyboard and gamepad.

Method Details

InputState() public method

Constructs a new input state.
public InputState ( ) : Microsoft.Xna.Framework
return Microsoft.Xna.Framework

IsMenuCancel() public method

Checks for a "menu cancel" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When the action is detected, the output playerIndex reports which player pressed it.
public IsMenuCancel ( PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool
controllingPlayer PlayerIndex
playerIndex PlayerIndex
return bool

IsMenuDown() public method

Checks for a "menu down" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.
public IsMenuDown ( PlayerIndex controllingPlayer ) : bool
controllingPlayer PlayerIndex
return bool

IsMenuLeft() public method

Checks for a "menu left" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.
public IsMenuLeft ( PlayerIndex controllingPlayer ) : bool
controllingPlayer PlayerIndex
return bool

IsMenuRight() public method

Checks for a "menu right" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.
public IsMenuRight ( PlayerIndex controllingPlayer ) : bool
controllingPlayer PlayerIndex
return bool

IsMenuSelect() public method

Checks for a "menu select" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When the action is detected, the output playerIndex reports which player pressed it.
public IsMenuSelect ( PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool
controllingPlayer PlayerIndex
playerIndex PlayerIndex
return bool

IsMenuUp() public method

Checks for a "menu up" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.
public IsMenuUp ( PlayerIndex controllingPlayer ) : bool
controllingPlayer PlayerIndex
return bool

IsMouseMoved() public method

Helper for checking if the position of the mouse has changed during this update.
public IsMouseMoved ( ) : bool
return bool

IsNewButtonPress() public method

Helper for checking if a button was newly pressed during this update. This method is designed for use in one-player games and only checks the gamepad for player one.
public IsNewButtonPress ( Buttons button ) : bool
button Buttons
return bool

IsNewButtonPress() public method

Helper for checking if a button was newly pressed during this update. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When a button press is detected, the output playerIndex reports which player pressed it.
public IsNewButtonPress ( Buttons button, PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool
button Buttons
controllingPlayer PlayerIndex
playerIndex PlayerIndex
return bool

IsNewKeyPress() public method

Helper for checking if a key was newly pressed during this update. This method is designed for use in PC games where there is only one keyboard.
public IsNewKeyPress ( Keys key ) : bool
key Keys
return bool

IsNewKeyPress() public method

Helper for checking if a key was newly pressed during this update. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When a keypress is detected, the output playerIndex reports which player pressed it.
public IsNewKeyPress ( Keys key, PlayerIndex controllingPlayer, PlayerIndex &playerIndex ) : bool
key Keys
controllingPlayer PlayerIndex
playerIndex PlayerIndex
return bool

IsNewMouseButtonPress() public method

Helper for checking if a mouse button was newly pressed during this update. No controlling player parameter is required because there is only one mouse.
public IsNewMouseButtonPress ( MouseButtons button ) : bool
button MouseButtons
return bool

IsPauseGame() public method

Checks for a "pause the game" input action. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player.
public IsPauseGame ( PlayerIndex controllingPlayer ) : bool
controllingPlayer PlayerIndex
return bool

Update() public method

Reads the latest state of the keyboard and gamepad.
public Update ( ) : void
return void

Property Details

CurrentGamePadStates public_oe property

public GamePadState[],Microsoft.Xna.Framework.Input CurrentGamePadStates
return Microsoft.Xna.Framework.Input.GamePadState[]

CurrentKeyboardStates public_oe property

public KeyboardState[],Microsoft.Xna.Framework.Input CurrentKeyboardStates
return Microsoft.Xna.Framework.Input.KeyboardState[]

CurrentMousePosition public_oe property

public Vector2,Microsoft.Xna.Framework CurrentMousePosition
return Microsoft.Xna.Framework.Vector2

CurrentMouseState public_oe property

public MouseState,Microsoft.Xna.Framework.Input CurrentMouseState
return Microsoft.Xna.Framework.Input.MouseState

GamePadWasConnected public_oe property

public bool[] GamePadWasConnected
return bool[]

LastGamePadStates public_oe property

public GamePadState[],Microsoft.Xna.Framework.Input LastGamePadStates
return Microsoft.Xna.Framework.Input.GamePadState[]

LastKeyboardStates public_oe property

public KeyboardState[],Microsoft.Xna.Framework.Input LastKeyboardStates
return Microsoft.Xna.Framework.Input.KeyboardState[]

LastMouseState public_oe property

public MouseState,Microsoft.Xna.Framework.Input LastMouseState
return Microsoft.Xna.Framework.Input.MouseState