# fnkg-keytranslator

> Translator for KeyboardEvent.key variants of different browsers

Latest version **1.0.1** (published 2019-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install fnkg-keytranslator
pnpm add fnkg-keytranslator
yarn add fnkg-keytranslator
bun add fnkg-keytranslator
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-20 |
| First published | 2019-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ramon Klein |
| Maintainers | weirdwizard |
| Keywords | typescript, javascript, keycodes, key, ts, event.key |

## Links

- npm: https://www.npmjs.com/package/fnkg-keytranslator
- Repository: https://github.com/miller45/fnkg-keytranslator
- Homepage: https://github.com/miller45/fnkg-keytranslator#readme
- Issues: https://github.com/miller45/fnkg-keytranslator/issues
- npm.io page: https://npm.io/package/fnkg-keytranslator

## 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.1 (latest) — 2019-08-20
- 1.0.0 — 2019-03-20

## README

# fnkg-keytranslator


Translates the KeyboardEvent.key code (which is the "offical" successor of KeyboardEvent.keyCode) to value common on all browsers.

The KeyboardEvent.keyCode is deprecated according to this source: https://developer.mozilla.org/de/docs/Web/API/KeyboardEvent/keyCode.
If you are using typescript and are using the keyCode you are probably seeing the 'keyCode is deprecated' message'.

The problem with using the successor KeyboardEvent.key, is that the codes differ among browsers (see https://caniuse.com/#search=KeyboardEvent.key)
This package provides the function KeyTranslate which will translate any given Event parameter to a uniform 'key' result which
conforms to this standard: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values

The 'key' value can then be used in conjunction with the package ts-key-enum : https://www.npmjs.com/package/ts-key-enum.

# Example

```typescript

import { Key } from 'ts-key-enum';
import { KeyTranslate } from 'fnkg-keytranslator';

...
onKeydown(event: KeyboardEvent) {
  const tkey = KeyTranslate(event);
  switch (tkey) {
    case Key.ArrowUp:
      // do something when user pressed the directional up key.
      console.log('up');
      break;
    case Key.ArrowDown:
      // do something when user pressed the directional down key.
      console.log('down');
      break;
  }
}
```

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