Merge pull request #2164 from hankbao/global-shortcut-doc-update
Update global-shortcut.md
This commit is contained in:
commit
a24d2921af
1 changed files with 19 additions and 11 deletions
|
@ -3,25 +3,33 @@
|
||||||
The `global-shortcut` module can register/unregister a global keyboard shortcut
|
The `global-shortcut` module can register/unregister a global keyboard shortcut
|
||||||
in operating system, so that you can customize the operations for various shortcuts.
|
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.
|
Note that the shortcut is global, even if the app does not get focused, it will still work.
|
||||||
|
You should not use this module until the ready event of app module gets emitted.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
var app = require('app');
|
||||||
var globalShortcut = require('global-shortcut');
|
var globalShortcut = require('global-shortcut');
|
||||||
|
|
||||||
// Register a 'ctrl+x' shortcut listener.
|
app.on('ready', function() {
|
||||||
var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed'); })
|
// Register a 'ctrl+x' shortcut listener.
|
||||||
|
var ret = globalShortcut.register('ctrl+x', function() {
|
||||||
|
console.log('ctrl+x is pressed');
|
||||||
|
})
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
console.log('registration failed');
|
console.log('registration failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether a shortcut is registered.
|
// Check whether a shortcut is registered.
|
||||||
console.log(globalShortcut.isRegistered('ctrl+x'));
|
console.log(globalShortcut.isRegistered('ctrl+x'));
|
||||||
|
});
|
||||||
|
|
||||||
// Unregister a shortcut.
|
app.on('will-quit', function() {
|
||||||
globalShortcut.unregister('ctrl+x');
|
// Unregister a shortcut.
|
||||||
|
globalShortcut.unregister('ctrl+x');
|
||||||
|
|
||||||
// Unregister all shortcuts.
|
// Unregister all shortcuts.
|
||||||
globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## globalShortcut.register(accelerator, callback)
|
## globalShortcut.register(accelerator, callback)
|
||||||
|
|
Loading…
Reference in a new issue