# KEYS

> Canonical `KeyboardEvent.key` constants — avoid magic strings in keydown handlers. The `WrKey` type is the union of every value, useful for narrowly-typed key callbacks.

Source: https://ngwr.dev/reference/utils/keys  
Kind: Util

## Usage

```angular-ts
import { KEYS, type WrKey } from 'ngwr/utils';

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

function onArrow(key: WrKey) { /* strictly-typed */ }
```

## Why ngwr provides this

`KeyboardEvent.key` is the standard, but the values are surprising: arrow keys are `'ArrowUp'` (not `'Up'`), space is `' '` (a literal space, not `'Space'`), and a typo like `'Esacpe'` silently never matches. `KEYS` gives you autocomplete, spec-correct values, and `WrKey` as a union for type-safe function signatures.

```angular-ts
// Native — string literals are typo-prone and the spec is surprising.
if (event.key === 'Esacpe') close();   // typo → silently never fires
if (event.key === 'Up') {} //          ← wrong, it's 'ArrowUp'
if (event.key === 'Space') {} //       ← wrong, it's ' ' (a literal space)

// ngwr — autocomplete + spec-correct + WrKey union for type-safe matching.
if (event.key === KEYS.ESCAPE) close();
if (event.key === KEYS.ARROW_UP) prev();
if (event.key === KEYS.SPACE) toggle();
```

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `KEYS` | Canonical `KeyboardEvent.key` constants — `ENTER`, `ESCAPE`, `ARROW_UP`, `ARROW_DOWN`, `TAB`, `SPACE`, … | `const record` | `—` |
| `WrKey` | Union of every value in `KEYS` — drop into function signatures for type-safe key matching. | `type alias` | `—` |

## See also

- [Keyboard](https://ngwr.dev/guides/keyboard) — How chords, keycaps and key primitives fit together in one task.
- [WrHotkey](https://ngwr.dev/reference/services/hotkey) — For whole chords, use the registry instead of comparing keys by hand.
- [hasModifier](https://ngwr.dev/reference/utils/has-modifier) — Is any modifier held?
- [isPrintableKey](https://ngwr.dev/reference/utils/is-printable-key) — Did the key produce a character?
