v0.0.14
utilities

Hotkeys

Tracks active keyboard keys and handles hotkey combinations with callback bindings.

  • All pressed keys :
  • Ctrl+a : false
  • Meta+e : false
  • Meta+z pressed : 0 times

Type Definition

Hotkeys

export declare class Hotkeys {
    constructor();

    /**
     * All active keys
     */
    get all(): string[];

    /**
     * Check if a key combinaison is active or not
     * @param keys
     * @returns
     */
    has: (keys: string | string[]) => boolean;

    /**
     * Listen key combinaison
     * @param keys
     * @param callback
     * @returns
     */
    on: (keys: string | string[], callback: (event: KeyboardEvent) => void) => () => void;
}

HotkeysOptions

export type HotkeysBinding = {
    combo: string[];
    callback: (event: KeyboardEvent) => void;
};

Credits

Runed