vkeys
v1.2.0
Published
map e.keyCode to vkey string
Maintainers
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 vkeysuse
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
- get the latest vkey module:
npm install --save-dev vkey - run the build:
npm run build
test
npm install -g browserify testling
npm run testlicense
MIT
