Convert between keyboard keycodes and keynames and vice versa.
Simple map of keyboard codes.
$ component install timoxley/keycode
var keycode = require'keycode';documentaddEventListener'keydown'console.log"You pressed" keycodee
keycode tries to make an intelligent guess as to what
you're trying to discover based on the type of argument
Returns the name of the key associated with this event.
documentbodyaddEventListener'keyup'console.logkeycodee // prints name of key
Due to the keypress event being weird,
keycodecurrently does not support the
keypress event, but this should not be an issue as
keyup work perfectly fine.
Returns the lowercase name of a given numeric keycode.
keycode13 // => 'enter'
Returns the numeric keycode for given key name.
keycode'Enter' // => 13// keycode is not case sensitivekeycode'eNtEr' // => 13
Common aliases are also supplied:
> for var alias in keycodealiases console.logalias keycodekeycodealiasctl ctrlpause pause/breakbreak pause/breakcaps caps lockescape escpgup page uppgdn page upins insertdel deletespc space
Key code/name maps are available directly as
keycodenames13 // => 'enter'keycodecodes'Enter' // => 13