gameplate - v2.2.0
    Preparing search index...

    Interface Keyboard

    Normalized keyboard state + event API. Wraps addEventListener('keydown' …) so you can write keyboard.onDown('ArrowRight', …) instead of filtering key codes yourself.

    Key strings follow the KeyboardEvent.key spec: 'ArrowUp', 'Enter', 'Escape', ' ' (space), 'a', etc.

    interface Keyboard {
        isDown: (key: string) => boolean;
        pressed: () => readonly string[];
        onDown: (
            key: string,
            handler: (event: KeyboardEvent) => void,
        ) => Unsubscribe;
        onUp: (key: string, handler: (event: KeyboardEvent) => void) => Unsubscribe;
        onAny: (
            handler: (event: KeyboardEvent, type: "down" | "up") => void,
        ) => Unsubscribe;
        destroy: () => void;
    }
    Index

    Properties

    isDown: (key: string) => boolean

    true while key is held.

    pressed: () => readonly string[]

    Snapshot of every currently-held key.

    onDown: (key: string, handler: (event: KeyboardEvent) => void) => Unsubscribe

    Fire handler once per real keydown for key (not repeats).

    onUp: (key: string, handler: (event: KeyboardEvent) => void) => Unsubscribe

    Fire handler on every keyup for key.

    onAny: (
        handler: (event: KeyboardEvent, type: "down" | "up") => void,
    ) => Unsubscribe

    Fire handler for any keydown/keyup. Useful for capture-all overlays.

    destroy: () => void

    Remove every listener and detach from the target. Idempotent.