1.0.3 • Published 3 years ago

w3c-keys v1.0.3

Weekly downloads
7,238
License
MIT
Repository
github
Last release
3 years ago

w3c-keys

Build Status npm version npm

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

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.
1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago