@jsvision/ui / createKeymap
Function: createKeymap()
createKeymap(
bindings):Keymap
Defined in: core/dist/engine/input/keymap.d.ts:41
Build a keymap from chord→name bindings.
Parameters
bindings
Readonly<Record<string, string>>
A map of chord strings (e.g. 'ctrl+s') to command names (e.g. 'save').
Returns
A compiled Keymap with a pure lookup.
Throws
If any binding is malformed (no key, unknown modifier, or unknown key name).
Example
ts
import { createKeymap, createDecoderState, decode } from '@jsvision/core';
const keymap = createKeymap({ 'ctrl+s': 'save', 'escape': 'cancel' });
// Ctrl+S arrives as the control byte 0x13.
const { events } = decode(Uint8Array.from([0x13]), createDecoderState());
for (const ev of events) {
if (ev.type === 'key') {
const command = keymap.lookup(ev); // 'save'
if (command) console.log('run command:', command);
}
}