Keyboard Class
Definition
Section titled “Definition”Represents the state of the keyboard.
public class KeyboardInheritance object
Constructors
Section titled “Constructors”Keyboard()
Section titled “Keyboard()”Creates a new instance of the keyboard manager.
public Keyboard()Fields
Section titled “Fields”RepeatDelay
Section titled “RepeatDelay”How often a key is included in the KeysPressed collection after the InitialRepeatDelay time has passed.
public TimeSpan RepeatDelayInitialRepeatDelay
Section titled “InitialRepeatDelay”The initial delay after a key is first pressed before it is included a second time (while held down) in the KeysPressed collection.
public TimeSpan InitialRepeatDelayProperties
Section titled “Properties”KeysPressed
Section titled “KeysPressed”A collection of keys registered as pressed which behaves like a command prompt when holding down keys. Uses the RepeatDelay and InitialRepeatDelay settings.
public ReadOnlyCollection<AsciiKey> KeysPressed { get; }KeysDown
Section titled “KeysDown”A collection of keys currently held down.
public ReadOnlyCollection<AsciiKey> KeysDown { get; }KeysReleased
Section titled “KeysReleased”A collection of keys that were just released this frame.
public ReadOnlyCollection<AsciiKey> KeysReleased { get; }HasKeysDown
Section titled “HasKeysDown”true when the KeysDown collection has at least one key; otherwise false.
public bool HasKeysDown { get; }HasKeysPressed
Section titled “HasKeysPressed”true when the KeysPressed collection has at least one key; otherwise false.
public bool HasKeysPressed { get; }Methods
Section titled “Methods”Clear()
Section titled “Clear()”Clears the KeysPressed, KeysDown, KeysReleased collections.
public void Clear()IsKeyUp(Keys)
Section titled “IsKeyUp(Keys)”Returns true if the key is not in the KeysDown collection regardless of shift state.
public bool IsKeyUp(Keys key)Parameters
Section titled “Parameters”key Keys
The key to check.
Returns
Section titled “Returns”bool
True when the key is not being pressed.
IsKeyUp(AsciiKey)
Section titled “IsKeyUp(AsciiKey)”Returns true if the key is not in the KeysDown collection.
public bool IsKeyUp(AsciiKey key)Parameters
Section titled “Parameters”key AsciiKey
The key to check.
Returns
Section titled “Returns”bool
True when the key is not being pressed.
IsKeyDown(Keys)
Section titled “IsKeyDown(Keys)”Returns true if the key is in the KeysDown collection regardless of shift state.
public bool IsKeyDown(Keys key)Parameters
Section titled “Parameters”key Keys
The key to check.
Returns
Section titled “Returns”bool
True when the key is being pressed.
IsKeyDown(AsciiKey)
Section titled “IsKeyDown(AsciiKey)”Returns true if the key is in the KeysDown collection.
public bool IsKeyDown(AsciiKey key)Parameters
Section titled “Parameters”key AsciiKey
The key to check.
Returns
Section titled “Returns”bool
True when the key is being pressed.
IsKeyReleased(Keys)
Section titled “IsKeyReleased(Keys)”Returns true when the key is in the KeysReleased collection regardless of shift state.
public bool IsKeyReleased(Keys key)Parameters
Section titled “Parameters”key Keys
The key to check.
Returns
Section titled “Returns”bool
True when the key was released this update frame.
IsKeyReleased(AsciiKey)
Section titled “IsKeyReleased(AsciiKey)”Returns true when the key is in the KeysReleased collection.
public bool IsKeyReleased(AsciiKey key)Parameters
Section titled “Parameters”key AsciiKey
The key to check.
Returns
Section titled “Returns”bool
True when the key was released this update frame.
IsKeyPressed(Keys)
Section titled “IsKeyPressed(Keys)”Returns true when the key is in the KeysPressed collection regardless of shift state.
public bool IsKeyPressed(Keys key)Parameters
Section titled “Parameters”key Keys
The key to check.
Returns
Section titled “Returns”bool
True when the key was considered first pressed.
IsKeyPressed(AsciiKey)
Section titled “IsKeyPressed(AsciiKey)”Returns true when the key is in the KeysPressed collection.
public bool IsKeyPressed(AsciiKey key)Parameters
Section titled “Parameters”key AsciiKey
The key to check.
Returns
Section titled “Returns”bool
True when the key was considered first pressed.
Update(TimeSpan)
Section titled “Update(TimeSpan)”Reads the keyboard state from GetKeyboardState().
public void Update(TimeSpan elapsedSeconds)Parameters
Section titled “Parameters”elapsedSeconds TimeSpan
Fractional seconds passed since Update was called.