https://github.com/ashubham/w3c-keys
keyboardEvent.key compatible key codes with Typescript Definitions.
https://github.com/ashubham/w3c-keys
html5 keyboard-events typescript w3c
Last synced: 22 days ago
JSON representation
keyboardEvent.key compatible key codes with Typescript Definitions.
- Host: GitHub
- URL: https://github.com/ashubham/w3c-keys
- Owner: ashubham
- License: mit
- Created: 2017-07-27T06:41:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-29T03:40:08.000Z (about 4 years ago)
- Last Synced: 2024-08-10T06:59:41.799Z (9 months ago)
- Topics: html5, keyboard-events, typescript, w3c
- Language: TypeScript
- Size: 56.6 KB
- Stars: 54
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# w3c-keys
[](https://travis-ci.org/ashubham/w3c-keys)
[](https://badge.fury.io/js/w3c-keys)
[](https://www.npmjs.com/package/w3c-keys)
keyboardEvent.key compatible key codes with Typescript Definitions.
Read https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
Compatible with IE/Edge/Safari Key idiosyncrasies.
Super Lightweight: ~900 Bytes Gzipped (Potentially smaller when combined gzipped with a bigger app)
## Usage
```typescript
import { Key } from 'w3c-keys';// To dispatch Events.
let evt = new KeyboardEvent('keydown', {
key: Key.Space
});
document.body.dispatchEvent(evt);// To check event keys.
document.body.on('keydown', (e) => {
if(e.key === Key.Backspace) {
// Do some shiz...
}
});
```## Why not use evt.which keyCodes ?
- `evt.which` keycodes are a deprecated standard.
- Ability to create synthetic key events is not possible with `evt.which`.