isomorphic-qwerty
Version:
Isomorphic coordinate-system for the QWERTY keyboard with sustain using the Shift key
61 lines (60 loc) • 2.11 kB
TypeScript
import { Coords3D } from './coordinates';
/**
* Keyboard event with a key code and coordinates if the device geometry can be figured out with any confidence.
*/
export type CoordinateKeyboardEvent = {
code: string;
coordinates?: Coords3D;
};
export type KeyupCallback = () => void;
export type KeydownCallback = (event: CoordinateKeyboardEvent) => KeyupCallback;
/**
* Keyboard event listener that filters out repeated keydown events and normalizes keycodes to coordinates.
* The Shift keys toggle 'sustain'.
*/
export declare class Keyboard {
private keydownCallbacks;
private keyupCallbacks;
private activeKeys;
private pendingKeys;
private stickyKeys;
private _keydown?;
private _keyup?;
private log;
/**
* Construct a new keyboard event listener.
* @param autobind Start listening to "keydown" and "keyup" events immediately.
* @param log Logging function.
*/
constructor(autobind?: boolean, log?: (msg: string) => void);
/**
* Stop listening to "keydown" and "keyup" events if constructed with `autobind = true`.
*/
dispose(): void;
/**
* Register a listener for processed keydown events.
* @param listener Function to call when a new key is pressed.
*/
addKeydownListener(listener: KeydownCallback): void;
/**
* Unregister a listener for processed keydown events.
* @param listener Callback registered with {@link Keyboard.addKeydownListener}.
*/
removeEventListener(listener: KeydownCallback): void;
private fireKeydown;
private fireKeyup;
/**
* Listener to be registered with `window.addEventListener("keydown", ...)`.
* @param event Keyboard event of a key being pressed down.
*/
keydown(event: KeyboardEvent): void;
/**
* Listener to be registered with `window.addEventListener("keyup", ...)`.
* @param event Keyboard event of a pressed key being released.
*/
keyup(event: KeyboardEvent): void;
/**
* Release keys sustained due to being pressed down with 'Shift'.
*/
deactivate(): void;
}