Skip to content

Commit

Permalink
Merge pull request electron#2164 from hankbao/global-shortcut-doc-update
Browse files Browse the repository at this point in the history
Update global-shortcut.md
  • Loading branch information
zcbenz committed Jul 10, 2015
2 parents 5ae57ba + fc9612a commit a24d292
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs/api/global-shortcut.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
The `global-shortcut` module can register/unregister a global keyboard shortcut
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.
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) {
console.log('registration failed');
}
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)
Expand Down

0 comments on commit a24d292

Please sign in to comment.