Table of Contents

Class Keyboard

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

The keyboard, from the OS's key events. Read it through Instance.

public class Keyboard
Inheritance
Keyboard
Inherited Members

Properties

Instance

The keyboard. It is created the first time it is used.

public static Keyboard Instance { get; }

Property Value

Keyboard

RepeatedKeys

The key-repeat events the OS delivered for this frame. A key held long enough appears once per repeat, so it can appear more than once in a slow frame, and not at all in a fast one.

public IReadOnlyList<Key> RepeatedKeys { get; }

Property Value

IReadOnlyList<Key>

Remarks

Frame-scoped state rather than a drain-once queue, deliberately. There is more than one reader - KeyboardManager feeds the UI, and the binding service feeds gameplay - and with a drain whichever of them ran first would silently take the repeats away from the other. Cleared once per frame by BSGameLib.Game.Input.Keyboard.BeginFrame(), before the event pump fills it again, so every reader in a frame sees the same thing.

Mirrors GetSnapshot() in standing aside for ImGui, so a debug panel with a focused text field does not also feed held keys to the game behind it.

Methods

ClearPressedKeys()

Forgets every key that is down.

public void ClearPressedKeys()

CreateTextInputHandler()

Creates a text input handler. It is disabled until IsEnabled is set to true.

public TextInput CreateTextInputHandler()

Returns

TextInput

GetSnapshot()

Returns the keys that are down now. Empty while ImGui has the keyboard.

public Keyboard.Snapshot GetSnapshot()

Returns

Keyboard.Snapshot

IsKeyDown(Key)

Whether the key is down now.

public bool IsKeyDown(Key key)

Parameters

key Key

Returns

bool

IsKeyUp(Key)

Whether the key is up now.

public bool IsKeyUp(Key key)

Parameters

key Key

Returns

bool

Events

KeyPressed

Raised when a key goes down. A repeat of a held key raises it too, with IsRepeat set.

public event EventHandler<KeyboardEventArgs> KeyPressed

Event Type

EventHandler<KeyboardEventArgs>

KeyReleased

Raised when a key goes up.

public event EventHandler<KeyboardEventArgs> KeyReleased

Event Type

EventHandler<KeyboardEventArgs>

TextInput

Raised for each character typed, while a TextInput is enabled.

public event EventHandler<KeyboardEventArgs> TextInput

Event Type

EventHandler<KeyboardEventArgs>