electron-shortcut-normalizer
v1.0.0
Published
Normalize electron keyboard shortcuts so they work on different operating systems
Downloads
234
Maintainers
Readme
electron-shortcut-normalizer
Normalize electron keyboard shortcuts so they work on different operating systems.
- [x] is a function
- [x] makes your electron keyboard shortcuts platform-agnostic
- [x] can make them platform-specific too
- [x] accepts target
platform
in an options object - [x] converts Option to Alt, because Alt exists on all platforms
- [x] converts
CmdOrCtrl
modifier toCommandOrControl
- [x] supports mixed-case modifiers like
MediaPreviousTrack
- [x] capitalizes first letter of each modifier
- [x] removes whitespace from shorcuts
- [x] converts hyphens (-) to plusses (+)
Installation
npm install electron-shortcut-normalizer --save
Usage
const normalize = require("electron-shortcut-normalizer")
normalize('Ctrl+A')
// => 'CommandOrControl+A'
normalize('CommandOrControl+Z', process.platform)
// => 'Command+Z' on Mac OS X
// => 'Control+Z' on Windows and Linux
normalize('CmdOrCtrl+a', 'darwin')
// => 'Command+A'
normalize('CmdOrCtrl+a', 'win32')
// => 'Control+A'
// `Option` is unique to Mac OS X, so it's normalized to `Alt`:
normalize('Option+Up')
// => 'Alt+Up'
For more specific usage information, see test.js
See Also
- Electron Accelerator docs
- Electron Menu docs
- Electron globalShortcut docs
- Node.js process.platform docs
- electron-localshortcut, a module to register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu.
Tests
npm install
npm test
Dependencies
None
Dev Dependencies
- tape: tap-producing test harness for node and browsers
- tap-spec: Formatted TAP output like Mocha's spec reporter
License
MIT
Generated by package-json-to-readme