Skip to content

Keyboard Class

Represents the state of the keyboard.

C#
public class Keyboard

Inheritance object

Creates a new instance of the keyboard manager.

C#
public Keyboard()

How often a key is included in the KeysPressed collection after the InitialRepeatDelay time has passed.

C#
public TimeSpan RepeatDelay

The initial delay after a key is first pressed before it is included a second time (while held down) in the KeysPressed collection.

C#
public TimeSpan InitialRepeatDelay

A collection of keys registered as pressed which behaves like a command prompt when holding down keys. Uses the RepeatDelay and InitialRepeatDelay settings.

C#
public ReadOnlyCollection<AsciiKey> KeysPressed { get; }

A collection of keys currently held down.

C#
public ReadOnlyCollection<AsciiKey> KeysDown { get; }

A collection of keys that were just released this frame.

C#
public ReadOnlyCollection<AsciiKey> KeysReleased { get; }

true when the KeysDown collection has at least one key; otherwise false.

C#
public bool HasKeysDown { get; }

true when the KeysPressed collection has at least one key; otherwise false.

C#
public bool HasKeysPressed { get; }

Clears the KeysPressed, KeysDown, KeysReleased collections.

C#
public void Clear()

Returns true if the key is not in the KeysDown collection regardless of shift state.

C#
public bool IsKeyUp(Keys key)

key Keys
The key to check.

bool
True when the key is not being pressed.

Returns true if the key is not in the KeysDown collection.

C#
public bool IsKeyUp(AsciiKey key)

key AsciiKey
The key to check.

bool
True when the key is not being pressed.

Returns true if the key is in the KeysDown collection regardless of shift state.

C#
public bool IsKeyDown(Keys key)

key Keys
The key to check.

bool
True when the key is being pressed.

Returns true if the key is in the KeysDown collection.

C#
public bool IsKeyDown(AsciiKey key)

key AsciiKey
The key to check.

bool
True when the key is being pressed.

Returns true when the key is in the KeysReleased collection regardless of shift state.

C#
public bool IsKeyReleased(Keys key)

key Keys
The key to check.

bool
True when the key was released this update frame.

Returns true when the key is in the KeysReleased collection.

C#
public bool IsKeyReleased(AsciiKey key)

key AsciiKey
The key to check.

bool
True when the key was released this update frame.

Returns true when the key is in the KeysPressed collection regardless of shift state.

C#
public bool IsKeyPressed(Keys key)

key Keys
The key to check.

bool
True when the key was considered first pressed.

Returns true when the key is in the KeysPressed collection.

C#
public bool IsKeyPressed(AsciiKey key)

key AsciiKey
The key to check.

bool
True when the key was considered first pressed.

Reads the keyboard state from GetKeyboardState().

C#
public void Update(TimeSpan elapsedSeconds)

elapsedSeconds TimeSpan
Fractional seconds passed since Update was called.