w3c-keys
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

w3c-keys

Build Status npm version npm

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

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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.316,310latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.316,310
1.0.230
1.0.134
1.0.02
0.3.6582
0.3.52
0.3.42
0.3.32
0.3.22
0.3.12
0.3.01

Package Sidebar

Install

npm i w3c-keys

Weekly Downloads

16,969

Version

1.0.3

License

MIT

Unpacked Size

35.3 kB

Total Files

13

Last publish

Collaborators

  • ashubham