UtilUpdated in v16Optional

WR_KEYS

KeyboardEvent.key constants, the WrKey union of their values, and WR_KEY_LABELS, what each key is called on a keycap.

Usage

import { WR_KEYS, type WrKey } from 'ngwr/utils';

if (event.key === WR_KEYS.ESCAPE) {
  close();
}

function onArrow(key: WrKey) { /* … */ }

Labels

WR_KEY_LABELS is keyed by WR_KEYS: Esc, Enter, Ctrl, an arrow as its glyph. English, as printed on a PC keycap. wrFormatChord in ngwr/hotkey prints a whole chord from it and swaps in Apple's glyphs on macOS; <wr-kbd> takes the words from the i18n catalog.

import { WR_KEYS, WR_KEY_LABELS } from 'ngwr/utils';

WR_KEY_LABELS[WR_KEYS.ESCAPE]; // 'Esc'
WR_KEY_LABELS[WR_KEYS.ARROW_UP]; // '↑'
WR_KEY_LABELS[event.key as WrKey] ?? event.key;

API

NameDescriptionTypeDefault
WR_KEYSKeyboardEvent.key values: ENTER, ESCAPE, ARROW_UP, ARROW_DOWN, TAB, SPACE, … and the modifiers CONTROL, SHIFT, ALT, META.const record—
WrKeyUnion of every value in WR_KEYS, for typed key parameters.type alias—
WR_KEY_LABELSWhat each key is called on a PC keycap, keyed by WR_KEYS: Esc, Ctrl, Page Up, ↑.Readonly<Record<WrKey, string>>-

See also