JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17228
  • Score
    100M100P100Q136738F
  • License MIT

keyboardEvent.key compatible key codes with Typescript Definitions. Edit

Package Exports

  • w3c-keys

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (w3c-keys) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

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 which is not possible with evt.which.