vkeys

mapping e.keyCode to human readable vkey

Showing:

Popularity

Downloads/wk

57

GitHub Stars

3

Maintenance

Last Commit

7yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

vkeys

problem

some browsers have got an e.key attribute that is submitted with keydown and keyup events. chrome (and other browsers) does not have a e.key attribute. there are also inconsistencies between different browsers.

solution

@chrisdickinson initiated a project vkey to collect the different definitions and merge them into a unified definition. for code that can not handle spaces, or wants less clutter, this transformation might be useful.

this module transforms the vkey definition, and removes the following clutter:

  • spaces
  • < and >
  • -
  • runs toLowerCase()

the output is a static key mapping file (without dynamic edge cases): vkeys.js

usage

install

npm install vkeys

use

var vkeys = require('./vkeys');

window.addEventListener('keydown', function(e) {
  console.log(vkeys[e.keyCode])
});

api

vkeys

Object with {code : key} pairs.

{
  0: 'unk',
  ...
  8: 'backspace',
  9: 'tab',
  12: 'clear',
  13: 'enter',
  ...
  254: 'clear'
}

see: vkeys.js

vkeys.getKey(code)

return the key for the given code.

var key = vkeys.getKey(60);
assert.equal(key, '<');

vkeys.findCode(key)

returns the first code that matches the key.

var code = vkeys.findCode('space');
assert.equal(code, 32);

vkeys.findAllCodes(key)

returns an Array of code's that match the key.

var code = vkeys.findAllCodes('meta');
// code equals [91, 92, 223, 224]

build

  1. get the latest vkey module: npm install --save-dev vkey
  2. run the build: npm run build

test

npm install -g browserify testling
npm run test

license

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial