Class Input
A static manger that polls keyboard, gamepad, and mouse states to provide unified access.
public static class Input
- Inheritance
-
Input
- Inherited Members
Properties
ControllerDeadZone
Gets or sets the threshold of detecting analog stick movement. Threshold is between 0.0 and 1.0. Default is 0.1.
public static float ControllerDeadZone { get; set; }
Property Value
HorizontalAxis
Gets the horizontal input axis based on the inputs of A/D, left/right arrows, DPad, and left stick.
public static int HorizontalAxis { get; }
Property Value
- int
-1 for left and 1 for right.
InputAxis
Gets the combined HorizontalAxis and VerticalAxis in a Microsoft.Xna.Framework.Point.
public static Point InputAxis { get; }
Property Value
- Point
Mouse
Gets the mouse handler instance for accessing the cursor positon and clicks.
public static MouseHandler Mouse { get; }
Property Value
VerticalAxis
Gets the vertical input axis based on the inputs of W/S, up/down arrows, DPad, and left stick.
public static int VerticalAxis { get; }
Property Value
- int
-1 for up and 1 for down.
Methods
Action(string)
Retrieves the InputAction object associated with the given name.
public static InputAction Action(string name)
Parameters
namestring
Returns
Add(string, Keys[], Buttons[])
Registers a new named input action binding specific keys and buttons to a single name.
public static void Add(string name, Keys[] keys, Buttons[] buttons)
Parameters
namestringThe unique name for the action.
keysKeys[]The keyboard keys that trigger this action.
buttonsButtons[]The gamepad buttons that trigger this action.
Exceptions
- Exception
Thrown if an action with the same name already exists.
IsButtonDown(Buttons)
Checks if the given gamepad button is currently held down.
public static bool IsButtonDown(Buttons button)
Parameters
buttonButtonsThe gamepad button to check.
Returns
IsButtonPressed(Buttons)
Checks if the given gamepad button was pressed this frame.
public static bool IsButtonPressed(Buttons button)
Parameters
buttonButtons
Returns
IsButtonReleased(Buttons)
Checks if the given gamepad button was released this frame.
public static bool IsButtonReleased(Buttons button)
Parameters
buttonButtons
Returns
IsDown(string)
Checks if the named action is currently held down.
public static bool IsDown(string name)
Parameters
namestringThe name of the action to check.
Returns
Exceptions
- Exception
Thrown if the action name does not exist.
IsKeyDown(Keys)
Checks if the given key is currently held down.
public static bool IsKeyDown(Keys key)
Parameters
keyKeysThe keyboard key to check.
Returns
- bool
trueif the key is down, otherwise,false.
IsKeyPressed(Keys)
Checks if the given key was pressed this frame.
public static bool IsKeyPressed(Keys key)
Parameters
keyKeys
Returns
Remarks
Returns true only on the single frame the key transitions from Up to Down.
IsKeyReleased(Keys)
Checks if the given key was released this frame.
public static bool IsKeyReleased(Keys key)
Parameters
keyKeys
Returns
Remarks
Returns true only on the single frame the key transitions from Down to Up.
IsPressed(string)
Checks if the named action was pressed this frame.
public static bool IsPressed(string name)
Parameters
namestringThe name of the action to check.
Returns
Exceptions
- Exception
Thrown if the action name does not exist.
IsReleased(string)
Checks if the named action was released this frame.
public static bool IsReleased(string name)
Parameters
namestringThe name of the action to check.
Returns
Exceptions
- Exception
Thrown if the action name does not exist.
Update(Rectangle)
Updates the current and previous input states.
public static void Update(Rectangle displayRect)
Parameters
displayRectRectangleThe current display rectangle.