Taos API Reference
    Preparing search index...

    Class KeyboardInput

    Robust held-key tracker for keyboard-driven controllers.

    Maintains a Set of currently-held KeyboardEvent.code values and — the whole point of this class — recovers from the cases where the browser never delivers the matching keyup, which would otherwise leave a key stuck "down" forever so the camera / player keeps moving after you let go:

    • window blur / Alt-Tab away — the browser stops sending key events to a background window, so the release is simply never seen. Cleared on blur.
    • tab hidden (switch tabs, minimize) — same problem; cleared on visibilitychange when document.hidden.
    • OS / Meta shortcuts (Win+Shift+S snip, macOS Cmd-combos) — the OS overlay grabs focus and swallows the keyup. Browsers also famously omit keyup for other keys while a Meta key is held. We clear everything on any Meta release as a catch-all, and expose metaHeld so controllers can ignore movement while the combo is in progress.

    keydown is ignored while a text input / textarea / contenteditable is focused so the player's typing isn't read as movement. keyup, by contrast, is ALWAYS processed regardless of target — clearing a key that isn't held is harmless, and unconditionally honoring releases avoids a key sticking when focus moved between the press and the release.

    Index

    Constructors

    Accessors

    • get metaHeld(): boolean

      True while a Windows / Meta (Cmd) key is held — controllers can gate movement on this.

      Returns boolean

    Methods

    • True if the given KeyboardEvent.code is currently held.

      Parameters

      • code: string

      Returns boolean

    • True if any of the given codes is currently held.

      Parameters

      • ...codes: string[]

      Returns boolean

    • Inject a key as if it were physically pressed. Use when the controller is attached after the real keydown already fired (e.g. a double-tap toggle).

      Parameters

      • code: string

      Returns void