Turn keyboard events into legible key names.
- Home: https://github.com/twhb/kee.js
- Demo: https://twhb.github.io/kee.js/demo.html
- npm: kee
This library exists because the same few bugs show up in most websites that implement keyboard shortcuts:
- Poor cross-OS support
- Poor cross-browser support
- Modifiers are sometimes ignored
- Key handling code is unreadable and difficult to maintain
Code using kee.js will neither have any of these issues, nor ever need to consider them.
Returns a string naming the key press than generated event
.
event: A KeyboardEvent
with type 'keyup'
or 'keydown'
.
Key press strings consist of all held modifiers, each followed by "+", follwed by the pressed key.
A key's name is its physical label, in lower case, with spaces removed. It is not always what the press would type - for example, "shift" types nothing, and "shift+4" types "$" (on a US keyboard).
Modifiers are "ctrl", "alt", "shift", and "windows", and always appear in that order. macOS's "Command" is given as "ctrl", and its Option as "alt".
If a key press can't be identified then the string 'unidentified'
is returned. This shouldn't happen except on custom hardware.