Simple map of keyboard codes.
$ component install timoxley/keycode
var keycode = require('keycode');
document.addEventListener('keydown', function(e) {
console.log("You pressed", keycode(e.keyCode))
})The keycode method responds differently depending on whether you're
looking up a keycode or a keyname.
##keycode(keycode:Number)
Returns the lowercase title for given numeric keycode.
keycode(13) // => 'enter'##keycode(title:String)
Returns numeric keycode for given key title.
keycode('Enter') // => 13Letter casing is insensitive so the following will still work.
keycode('eNtEr') // => 13KeyCode and KeyName maps are available directly as keycode.code and keycode.title respectively.
keycode.title[13] // => 'enter'
keycode.code['Enter'] // => 13Due to the keypress event being weird,keycode currently does not support the keypress event, but this should not be an issue as keydown and keyup work perfectly fine.
Original code lifted from http://jsfiddle.net/vWx8V/ via http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes