Documentation
    Preparing search index...

    Class KeyboardState

    Tracks which physical keys are currently held on a KeySurface.

    Construction registers listeners; KeyboardState.dispose removes them. A caller that never disposes leaks two listeners and keeps the surface alive, which is why dispose is idempotent and safe to call from a teardown path that may run twice.

    Index
    • Parameters

      • surface: KeySurface

        Where key events arrive. In a browser this is window; tests pass a fake, which is what makes the focus-loss behaviour above testable without a DOM.

      Returns KeyboardState

    • get held(): ReadonlySet<string>

      Every held code, as a live read-only view.

      Live rather than a copy so a per-frame read allocates nothing (§7b); frozen so a caller cannot edit the set this class maintains.

      Returns ReadonlySet<string>

    • Removes every listener and forgets all state.

      Idempotent: a second call is a no-op rather than an error, so a teardown path that runs twice is not a defect.

      Returns void

    • Whether code — a KeyboardEvent.code, e.g. "KeyW" — is held now.

      Parameters

      • code: string

      Returns boolean