Update sample code in global-shortcut.md
This commit is contained in:
parent
7b19b6b4f2
commit
fb99bfac52
1 changed files with 18 additions and 11 deletions
|
@ -6,10 +6,14 @@ Note that the shortcut is global, even if the app does not get focused, it will
|
||||||
You should not use this module until the ready event of app module gets emitted.
|
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');
|
||||||
|
|
||||||
|
app.on('ready', function() {
|
||||||
// Register a 'ctrl+x' shortcut listener.
|
// Register a 'ctrl+x' shortcut listener.
|
||||||
var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed'); })
|
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');
|
||||||
|
@ -17,12 +21,15 @@ if (!ret) {
|
||||||
|
|
||||||
// Check whether a shortcut is registered.
|
// Check whether a shortcut is registered.
|
||||||
console.log(globalShortcut.isRegistered('ctrl+x'));
|
console.log(globalShortcut.isRegistered('ctrl+x'));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('will-quit', function() {
|
||||||
// Unregister a shortcut.
|
// Unregister a shortcut.
|
||||||
globalShortcut.unregister('ctrl+x');
|
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