|
| 1 | +# types-keyboardevent |
| 2 | + |
| 3 | +**types-keyboardevent** provides TypeScript types for `KeyboardEvent`, |
| 4 | +generated directly from W3C UI Events KeyboardEvent specifications. |
| 5 | + |
| 6 | +```bash |
| 7 | +npm install types-keyboardevent |
| 8 | +``` |
| 9 | + |
| 10 | +- `KeyboardEventCode` represents a union of known `event.code` values. |
| 11 | +- `KeyboardEventKey` represents a union of known `event.key` values. |
| 12 | +- Includes sub-types such as `KeyboardEventCode.Numpad` and `KeyboardEventKey.Navigation`. |
| 13 | +- Source is generated directly from: |
| 14 | + - https://w3c.github.io/uievents-code/ |
| 15 | + - https://w3c.github.io/uievents-key/ |
| 16 | + |
| 17 | +This package is type-only at runtime. |
| 18 | +Its JavaScript entrypoints intentionally export no values. |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```ts |
| 23 | +import type { KeyboardEventCode, KeyboardEventKey } from "types-keyboardevent"; |
| 24 | + |
| 25 | +const isMovementCode = (code: KeyboardEventCode.Arrowpad) => code === "ArrowLeft" || code === "ArrowRight"; |
| 26 | + |
| 27 | +const isConfirmKey = (key: KeyboardEventKey) => key === "Enter" || key === " "; |
| 28 | +``` |
| 29 | + |
| 30 | +You can also import the type families directly from their subpaths: |
| 31 | + |
| 32 | +```ts |
| 33 | +import type { KeyboardEventCode } from "types-keyboardevent/KeyboardEventCode"; |
| 34 | +import type { KeyboardEventKey } from "types-keyboardevent/KeyboardEventKey"; |
| 35 | +``` |
| 36 | + |
| 37 | +## API surface |
| 38 | + |
| 39 | +### `KeyboardEventCode` |
| 40 | + |
| 41 | +Includes values such as `"KeyA"`, `"ArrowRight"`, `"NumpadEnter"`, and media-related codes. |
| 42 | + |
| 43 | +Useful namespaces include: |
| 44 | + |
| 45 | +- `KeyboardEventCode.Modifier` |
| 46 | +- `KeyboardEventCode.Arrowpad` |
| 47 | +- `KeyboardEventCode.Numpad` |
| 48 | +- `KeyboardEventCode.Function` |
| 49 | +- `KeyboardEventCode.Media` |
| 50 | + |
| 51 | +### `KeyboardEventKey` |
| 52 | + |
| 53 | +Includes values such as `"Enter"`, `"ArrowRight"`, `"AudioVolumeUp"`, and `"MediaPlayPause"`. |
| 54 | + |
| 55 | +Useful namespaces include: |
| 56 | + |
| 57 | +- `KeyboardEventKey.Modifier` |
| 58 | +- `KeyboardEventKey.Navigation` |
| 59 | +- `KeyboardEventKey.Editing` |
| 60 | +- `KeyboardEventKey.Multimedia` |
| 61 | +- `KeyboardEventKey.Audio` |
| 62 | +- `KeyboardEventKey.Browser` |
| 63 | + |
| 64 | +## License |
| 65 | + |
| 66 | +[MIT-0](./LICENSE.md) |
0 commit comments