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