keyboard-shortcut-string
v2.0.1
Published
Creates a canonical keyboard shortcut string from a shortcut source string
Downloads
3
Readme
Keyboard Shortcut String
Creates a canonical keyboard shortcut string from the given shortcut string input.
This module does not bind shortcuts to keyboard events – its only job is to parse shortcut strings, and return predictable results. A good use for this module would be to support a keystroke module's event handler mapping.
Examples:
console.log(getCanonicalShortcut('ctrl s'));
// 'ctrl s'
console.log(getCanonicalShortcut('s ctrl'));
// 'ctrl s'
console.log(getCanonicalShortcut('s ctrl'));
// 'ctrl s'
console.log(getCanonicalShortcut('shift ctrl s'));
// 'shift ctrl s'
console.log(getCanonicalShortcut('ctrl shift s'));
// 'shift ctrl s'
console.log(getCanonicalShortcut('S CTRL SHIFT'));
// 'shift ctrl s'
Modifier Keys
- shift
- ctrl
- alt
- meta
Modifier keys are extracted from the input and placed in a predictable order at the front of the result.
Non-modifier Keys
Only one non-modifier key component is allowed: "alt s"
works, but "alt s h"
will throw.
Non-modifier keys can be almost anything: "s", "S", "space", "ESC", and lowercase is always returned.
Thanks!
This source is heavily sourced from MooTools Keyboard.parse.
License
MIT