Class KeyboardDriver

A generic keyboard driver.

Does nothing on its own, but provides an API for sending keyboard events to registered roots.

Hierarchy

Implements

Constructors

Properties

eventQueues: Map<Root, KeyEvent[]> = ...

The list of key down/up events that haven't been dispatched yet.

focus: null | Root = null

The currently focused root. New keyboard events will go to this root

keysDown: Set<string> = ...

A set containing the keys currently down.

lastActivity: null | Root = null

The last Root that had "activity"; the last Root where any focus was grabbed. Used as a fallback when there is no focus. If this is null, then a root from eventQueues is picked; this fallback of a fallback may result in weird behaviour if there are more than 1 Roots, since eventQueues is a Map, and Map iteration is not guaranteed to be in the same order

Accessors

  • get needsInput(): boolean
  • Check if the currently focused root needs keyboard input. Virtual keyboard should query this property to know when to show themselves.

    Returns boolean

Methods

  • Push a new KeyPress event to eventQueues.

    Parameters

    • key: string

      Must follow the KeyboardEvent.key Web API.

    • shift: boolean

      Is shift being pressed?

    • ctrl: boolean

      Is control being pressed?

    • alt: boolean

      Is alt being pressed?

    Returns void

  • Calls keyDown followed by keyUp. If the key was already down before calling (isKeyDown), keyUp is not called.

    Parameters

    • key: string

      Must follow the KeyboardEvent.key Web API.

    • shift: boolean

      Is shift being pressed?

    • ctrl: boolean

      Is control being pressed?

    • alt: boolean

      Is alt being pressed?

    Returns void

  • Does nothing if the new focus type is not a Keyboard. If the focus comes from a root which is not the root focus, then the root focus is changed to the new root. If there is no new focused widget (the root's keyboard focus was cleared), then nothing happens.

    This behaviour is confusing, however, it's required so that the keyboard focus "lingers" for future tab key presses; this way, pressing tab can do tab selection even when there is no widget that wants keyboard input. When a focus is lingering, then it means that key events are still being dispatched to the last focused root, but they don't have a target. This way, most events get dropped, but tab key events are used for tab selection.

    Parameters

    Returns void

Generated using TypeDoc