# ts-keycode-enum

> A TypeScript enum definition that maps human-friendly key names to JavaScript key codes

Latest version **1.0.6** (published 2018-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-keycode-enum
pnpm add ts-keycode-enum
yarn add ts-keycode-enum
bun add ts-keycode-enum
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-06-18 |
| First published | 2017-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | Nathan Friend |
| Maintainers | nathanfriend |
| Keywords | typescript, javascript, keycodes, key, enum, ts |

## Links

- npm: https://www.npmjs.com/package/ts-keycode-enum
- Repository: https://github.com/nfriend/ts-keycode-enum
- Homepage: https://github.com/nfriend/ts-keycode-enum#readme
- Issues: https://github.com/nfriend/ts-keycode-enum/issues
- npm.io page: https://npm.io/package/ts-keycode-enum

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-06-18
- 1.0.5 — 2018-06-13
- 1.0.4 — 2017-03-20
- 1.0.3 — 2017-03-20
- 1.0.2 — 2017-02-13
- 1.0.1 — 2017-02-10
- 1.0.0 — 2017-02-10

## README

# ts-keycode-enum
A TypeScript enum definition that maps human-friendly key names to JavaScript key codes

<img align="right" src="https://raw.githubusercontent.com/nfriend/ts-keycode-enum/master/logo.jpg" />

## Important note

[`event.which`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which) and [`event.keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) have been deprecated.  It is recommended to instead use [`event.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) in combination with this very similar module: [ts-key-enum](https://github.com/nfriend/ts-key-enum).

## Install

```bash
npm install ts-keycode-enum --save
```

## Purpose

Tired of referencing JavaScript keycodes by number?

```JavaScript
onKeyPress = (ev) => {

    // gross
    if (ev.which === 13) {
        ...
    }
}
```

Me too.  With this module, you can do this instead (in a TypeScript file):

```JavaScript
onKeyPress = (ev) => {

    // much better
    if (ev.which === Key.Enter) {
        ...
    }
}
```

## Usage

To use this module, import the `Key` enum at the top of your TypeScript file using the enum:

```JavaScript
import { Key } from 'ts-keycode-enum';
```

You can now use a readable enum value in place of any raw keycodes throughout the file:

```JavaScript
if (ev.which === Key.Escape) { ... }
```

See [Key.enum.ts](./Key.enum.ts) for a complete list of available keys.

In addition, to aid with readability, a number of enum values have aliases.  For example:

```JavaScript
// this  true - these values are equal
Key.One === Key.ExclamationMark
```

Use whichever value makes more sense for readability.

## Building

To build this module yourself, first install its dependencies using

```bash
npm install
```

Then, run the build using

```bash
npm run build
```

Build output is placed in the `dist` directory.

## Contributions

This module only contains some of the most commonly-used key codes.  If it's missing keycodes that you need, feel free to request the codes via an issue or a pull request.

## License

MIT

---
_Source: https://npm.io/package/ts-keycode-enum · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
