Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gamestdio/keycode
Use human key names instead of keycode numbers for your keyboard bindings.
https://github.com/gamestdio/keycode
keycode
Last synced: 9 days ago
JSON representation
Use human key names instead of keycode numbers for your keyboard bindings.
- Host: GitHub
- URL: https://github.com/gamestdio/keycode
- Owner: gamestdio
- License: mit
- Created: 2015-09-22T20:14:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-16T13:45:51.000Z (about 7 years ago)
- Last Synced: 2024-10-12T04:57:07.535Z (about 1 month ago)
- Topics: keycode
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 21
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @gamestdio/keycode
Use human key names instead of keycode numbers for your keyboard bindings.
**1.7kb minified**
## Warning
The [`which`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which) and [`keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) properties are in the process of being deprecated by the browsers.
After mainstream adoption, you would rather use the new [`key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) or [`code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code) attributes in `KeyboardEvent`.
By the time of this writing, IE/Edge still doesn't support the new `KeyboardEvent.key` / `KeyboardEvent.code` API. See: https://caniuse.com/#feat=keyboardevent-code
## Usage example
```typescript
import * as Keycode from "@gamestdio/keycode";document.addEventListener('keyup', function(e) {
if (e.which == Keycode.ENTER) {
console.log("User pressed ENTER key")
}
})
```## License
MIT