2.0.1 • Published 8 years ago

keyboard-shortcut-string v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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

  1. shift
  2. ctrl
  3. alt
  4. 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