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,23 +6,30 @@ 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.
|
||||
|
||||
```javascript
|
||||
var app = require('app');
|
||||
var globalShortcut = require('global-shortcut');
|
||||
|
||||
// Register a 'ctrl+x' shortcut listener.
|
||||
var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed'); })
|
||||
app.on('ready', function() {
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether a shortcut is registered.
|
||||
console.log(globalShortcut.isRegistered('ctrl+x'));
|
||||
// Check whether a shortcut is registered.
|
||||
console.log(globalShortcut.isRegistered('ctrl+x'));
|
||||
});
|
||||
|
||||
// Unregister a shortcut.
|
||||
globalShortcut.unregister('ctrl+x');
|
||||
app.on('will-quit', function() {
|
||||
// Unregister a shortcut.
|
||||
globalShortcut.unregister('ctrl+x');
|
||||
|
||||
// Unregister all shortcuts.
|
||||
globalShortcut.unregisterAll();
|
||||
// Unregister all shortcuts.
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
```
|
||||
|
||||
## globalShortcut.register(accelerator, callback)
|
||||
|
|
Loading…
Reference in a new issue