https://github.com/ttse76/keypress-util
Utility to identify keycodes for keyboard keys
https://github.com/ttse76/keypress-util
keyboard keycode keypress keys module node nodejs react utility
Last synced: 3 months ago
JSON representation
Utility to identify keycodes for keyboard keys
- Host: GitHub
- URL: https://github.com/ttse76/keypress-util
- Owner: ttse76
- Created: 2022-07-13T21:15:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-13T22:15:33.000Z (over 3 years ago)
- Last Synced: 2025-09-26T09:58:28.225Z (6 months ago)
- Topics: keyboard, keycode, keypress, keys, module, node, nodejs, react, utility
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/keypress-util
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Keypress Util

A lightweight module for getting keycodes
## Installation
`npm i keypress-util`
## Usage
To find a key, import the `KEY_CODES` object, then find the key in the list of keys.
```javascript
const { KEY_CODES } = require('keypress-util');
const code = KEY_CODES.SHIFT; // 16
```
To get a key based on a code, import the `getKey` function. All keycodes are numbers, `getKey` returns `"NONE"` if the keycode is either not a number or an invalid key. Numbers as a string are valid as long as the number is a valid keycode.
```javascript
const { getKey } = require('keypress-util');
const k0 = getKey(16); // "SHIFT"
const k1 = getKey('45') // "INSERT"
const k2 = getKey(500); // "NONE"
const k3 = getKey("Invalid Key"); // "NONE"
```