UNPKG

tinykeys

Version:

A tiny (~400 B) & modern library for keybindings.

30 lines (29 loc) 761 B
/** * A map of keybinding strings to event handlers. */ export interface KeyBindingMap { [keybinding: string]: (event: KeyboardEvent) => void; } /** * Subscribes to keybindings. * * Returns an unsubscribe method. * * @example * ```js * import keybindings from "../src/keybindings" * * keybindings(window, { * "Shift+d": () => { * alert("The 'Shift' and 'd' keys were pressed at the same time") * }, * "y e e t": () => { * alert("The keys 'y', 'e', 'e', and 't' were pressed in order") * }, * "$mod+d": () => { * alert("Either 'Control+d' or 'Meta+d' were pressed") * }, * }) * ``` */ export default function keybindings(target: Window | HTMLElement, keyBindingMap: KeyBindingMap): () => void;