Table of Contents

Class KeyboardManager

Namespace
BSGameLib.Game.Input
Assembly
BSGameLib.Game.dll

The default keyboard manager. It tracks which keys went down or up between frames.

public class KeyboardManager : IKeyboardManager
Inheritance
KeyboardManager
Implements
Inherited Members

Constructors

KeyboardManager(ILogger<KeyboardManager>)

Created by dependency injection. Reads the keyboard once, so that the first frame has a previous state.

public KeyboardManager(ILogger<KeyboardManager> logger)

Parameters

logger ILogger<KeyboardManager>

Properties

CurrentState

The keyboard state this frame.

public Keyboard.Snapshot CurrentState { get; }

Property Value

Keyboard.Snapshot

KeysDown

The keys that went down since the last frame.

public IEnumerable<Key> KeysDown { get; }

Property Value

IEnumerable<Key>

KeysPressed

The keys held down this frame.

public IEnumerable<Key> KeysPressed { get; }

Property Value

IEnumerable<Key>

KeysRepeated

Keys the OS repeated this frame because they are being held. Empty on the frame a key is first pressed - that one is in KeysDown - and a key held long enough appears here once per repeat, so it can appear more than once in a slow frame.

public IEnumerable<Key> KeysRepeated { get; }

Property Value

IEnumerable<Key>

Remarks

Separate from KeysDown rather than folded into it, because most actions must NOT repeat: held movement is read as a level and paced by the game, and a held Enter must not submit a form thirty times a second. Repeating is opt-in, and the handlers that want it are the text-editing ones.

KeysUp

The keys that went up since the last frame.

public IEnumerable<Key> KeysUp { get; }

Property Value

IEnumerable<Key>

PreviousState

The keyboard state the frame before.

public Keyboard.Snapshot PreviousState { get; }

Property Value

Keyboard.Snapshot

Methods

IsKeyPressed(Key)

Whether the key went down this frame.

public bool IsKeyPressed(Key key)

Parameters

key Key

Returns

bool

IsKeyReleased(Key)

Whether the key went up this frame.

public bool IsKeyReleased(Key key)

Parameters

key Key

Returns

bool

Update(IGameTime)

Reads the keyboard for this frame.

public void Update(IGameTime gameTime)

Parameters

gameTime IGameTime