ShortE
Keyboard shortcut modes for Electron
Description
This allows you to designate a 'leader' key, that enters the user into a different 'mode'. Upon entering the new mode:
- Your pre-defined shortcuts are registered and available to the user.
- When using one of those shortcuts, a debouncing timer starts, at the end of which the user will return to the previous mode.
- The user can press the 'cancel' shortcut to return to the previous mode.
Installation
npm install shorte
Usage
const ShortE = const globalShortcut = // ...app
API
contructor
const shortcuts = globalShortcut leader opts
Cteates the shortcuts object and registers the leader key.
- globalShortcut - the electron globalShortcut object
- leader - the leader key (electron Accelerator format) (eg. 'Ctrl+B')
- opts - optional object including:
- debounceTime (in milliseconds) - default is 0
- cancel - string for custom button - default is Esc
register
shortcuts
Registers a shortcut key. Once the leader key will be pressed, this shortcut will be available.
- key: The key combination in electron Accelerator format. (eg. 'Alt+B')
- cb: The function to be called when this key is pressed.
leader
shortcuts
Changes the leader key.
- key: the new leader key
cancel
shortcuts
Changes the cancel key.
- key: the new cancel key
Accessors
debounceTime
console // 500shortcutsdebounceTime = 100console // 100
shortcuts
console // { a: [ some function ], b: [ some other function] }shortcutsshortcuts => {} // silently fail
active
// Press leader keyconsole // true// Press a shortcut, wait debounceTimeconsole // false
Events
active
shortcuts// Press leader key// 'leader key pressed, shortcuts now available
inactive
shortcuts// Press leader key// Use shortcut and wait debounce time, or press cancel key// 'timeout reached, shortcuts unavailable'
Contributing
Yes please.
License
MIT