# WR_KEYS

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

Source: https://ngwr.dev/reference/utils/wr-keys  
Kind: Util  
Updated in v16  
Optional

## Usage

```angular-ts
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.

```angular-ts
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

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `WR_KEYS` | `KeyboardEvent.key` values: `ENTER`, `ESCAPE`, `ARROW_UP`, `ARROW_DOWN`, `TAB`, `SPACE`, … and the modifiers `CONTROL`, `SHIFT`, `ALT`, `META`. | `const record` | `—` |
| `WrKey` | Union of every value in `WR_KEYS`, for typed key parameters. | `type alias` | `—` |
| `WR_KEY_LABELS` | What each key is called on a PC keycap, keyed by `WR_KEYS`: `Esc`, `Ctrl`, `Page Up`, `↑`. | `Readonly<Record<WrKey, string>>` | `-` |

## See also

- [Keyboard](https://ngwr.dev/guides/keyboard) — Bind shortcuts, show them as keycaps, and see which keys each component handles.
- [WrHotkey](https://ngwr.dev/reference/services/hotkey) — For whole chords, and `wrFormatChord`.
- [wrHasModifier](https://ngwr.dev/reference/utils/wr-has-modifier) — True when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.
- [wrIsPrintableKey](https://ngwr.dev/reference/utils/wr-is-printable-key) — True for a single printable character typed without Ctrl, Cmd or Alt (Shift is allowed).
- [wrIsComposing](https://ngwr.dev/reference/utils/wr-is-composing) — True while an input method (IME) is composing, so the key belongs to it and not to your handler.
