2014-08-04 01:47:42 +00:00
|
|
|
# global-shortcut
|
|
|
|
|
|
|
|
The `global-shortcut` module can register/unregister a global keyboard shortcut
|
2015-06-07 01:46:51 +00:00
|
|
|
in operating system, so that you can customize the operations for various shortcuts.
|
|
|
|
Note that the shortcut is global, even if the app does not get focused, it will still work.
|
2014-08-04 01:47:42 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
var globalShortcut = require('global-shortcut');
|
|
|
|
|
|
|
|
// Register a 'ctrl+x' shortcut listener.
|
|
|
|
var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed'); })
|
2015-06-09 16:01:09 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
2015-06-09 14:49:21 +00:00
|
|
|
console.log('registration failed');
|
2015-06-09 16:01:09 +00:00
|
|
|
}
|
2014-08-04 01:47:42 +00:00
|
|
|
|
|
|
|
// Check whether a shortcut is registered.
|
|
|
|
console.log(globalShortcut.isRegistered('ctrl+x'));
|
|
|
|
|
|
|
|
// Unregister a shortcut.
|
|
|
|
globalShortcut.unregister('ctrl+x');
|
|
|
|
|
|
|
|
// Unregister all shortcuts.
|
|
|
|
globalShortcut.unregisterAll();
|
|
|
|
```
|
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
## globalShortcut.register(accelerator, callback)
|
2014-08-04 01:47:42 +00:00
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
* `accelerator` [Accelerator](accelerator.md)
|
2014-08-04 01:47:42 +00:00
|
|
|
* `callback` Function
|
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
Registers a global shortcut of `accelerator`, the `callback` would be called when
|
2014-08-04 01:47:42 +00:00
|
|
|
the registered shortcut is pressed by user.
|
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
## globalShortcut.isRegistered(accelerator)
|
2014-08-04 01:47:42 +00:00
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
* `accelerator` [Accelerator](accelerator.md)
|
2014-08-04 01:47:42 +00:00
|
|
|
|
2015-06-07 01:46:51 +00:00
|
|
|
Returns `true` or `false` depending on if the shortcut `accelerator` is registered.
|
2014-08-04 01:47:42 +00:00
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
## globalShortcut.unregister(accelerator)
|
2014-08-04 01:47:42 +00:00
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
* `accelerator` [Accelerator](accelerator.md)
|
2014-08-04 01:47:42 +00:00
|
|
|
|
|
|
|
Unregisters the global shortcut of `keycode`.
|
|
|
|
|
|
|
|
## globalShortcut.unregisterAll()
|
|
|
|
|
|
|
|
Unregisters all the global shortcuts.
|