Skip to content
Use human key names instead of keycode numbers for your keyboard bindings.
Branch: master
Clone or download
Latest commit d4045f7 Oct 16, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore using 'which' code instead of 'code'. Oct 15, 2017
LICENSE using 'which' code instead of 'code'. Oct 15, 2017
README.md update README. Oct 16, 2017
index.ts expose each keycode individually. closes #1 Oct 16, 2017
package.json
tsconfig.json using 'which' code instead of 'code'. Oct 15, 2017
yarn.lock use KeyboardEvent.code string constants. release v2 Jan 29, 2017

README.md

@gamestdio/keycode

Use human key names instead of keycode numbers for your keyboard bindings.

1.7kb minified

Warning

The which and keyCode properties are in the process of being deprecated by the browsers.

After mainstream adoption, you would rather use the new key or 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

import * as Keycode from "@gamestdio/keycode";

document.addEventListener('keyup', function(e) {
  if (e.which == Keycode.ENTER) {
    console.log("User pressed ENTER key")
  }
})

License

MIT

You can’t perform that action at this time.