2014-08-04 16:00:39 +00:00
|
|
|
# Accelerator
|
|
|
|
|
2016-04-21 22:39:12 +00:00
|
|
|
> Define keyboard shortcuts.
|
2016-04-21 22:35:29 +00:00
|
|
|
|
2016-10-26 12:48:09 +00:00
|
|
|
Accelerators are Strings that can contain multiple modifiers and key codes,
|
|
|
|
combined by the `+` character, and are used to define keyboard shortcuts
|
|
|
|
throughout your application.
|
2014-08-04 16:00:39 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2016-04-01 21:09:01 +00:00
|
|
|
* `CommandOrControl+A`
|
|
|
|
* `CommandOrControl+Shift+Z`
|
2014-08-04 16:00:39 +00:00
|
|
|
|
2016-10-26 12:48:09 +00:00
|
|
|
Shortcuts are registered with the [`globalShortcut`](global-shortcut.md) module
|
|
|
|
using the [`register`](global-shortcut.md#globalshortcutregisteraccelerator-callback)
|
|
|
|
method, i.e.
|
|
|
|
|
|
|
|
```javascript
|
2018-09-13 16:10:51 +00:00
|
|
|
const { app, globalShortcut } = require('electron')
|
2016-10-26 12:48:09 +00:00
|
|
|
|
|
|
|
app.on('ready', () => {
|
|
|
|
// Register a 'CommandOrControl+Y' shortcut listener.
|
|
|
|
globalShortcut.register('CommandOrControl+Y', () => {
|
|
|
|
// Do stuff when Y and either Command/Control is pressed.
|
|
|
|
})
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
## Platform notice
|
|
|
|
|
2015-07-23 16:55:57 +00:00
|
|
|
On Linux and Windows, the `Command` key does not have any effect so
|
2016-06-18 13:26:26 +00:00
|
|
|
use `CommandOrControl` which represents `Command` on macOS and `Control` on
|
2014-08-04 16:00:39 +00:00
|
|
|
Linux and Windows to define some accelerators.
|
|
|
|
|
2016-06-18 13:26:26 +00:00
|
|
|
Use `Alt` instead of `Option`. The `Option` key only exists on macOS, whereas
|
2016-04-01 22:48:12 +00:00
|
|
|
the `Alt` key is available on all platforms.
|
|
|
|
|
2015-07-24 06:19:43 +00:00
|
|
|
The `Super` key is mapped to the `Windows` key on Windows and Linux and
|
2016-06-18 13:26:26 +00:00
|
|
|
`Cmd` on macOS.
|
2015-04-28 05:28:18 +00:00
|
|
|
|
2014-08-04 16:00:39 +00:00
|
|
|
## Available modifiers
|
|
|
|
|
|
|
|
* `Command` (or `Cmd` for short)
|
|
|
|
* `Control` (or `Ctrl` for short)
|
|
|
|
* `CommandOrControl` (or `CmdOrCtrl` for short)
|
|
|
|
* `Alt`
|
2016-03-06 06:12:04 +00:00
|
|
|
* `Option`
|
|
|
|
* `AltGr`
|
2014-08-04 16:00:39 +00:00
|
|
|
* `Shift`
|
2015-04-28 05:28:18 +00:00
|
|
|
* `Super`
|
2014-08-04 16:00:39 +00:00
|
|
|
|
|
|
|
## Available key codes
|
|
|
|
|
|
|
|
* `0` to `9`
|
|
|
|
* `A` to `Z`
|
|
|
|
* `F1` to `F24`
|
|
|
|
* Punctuations like `~`, `!`, `@`, `#`, `$`, etc.
|
2015-01-23 23:26:54 +00:00
|
|
|
* `Plus`
|
2014-08-04 16:00:39 +00:00
|
|
|
* `Space`
|
2016-05-12 20:00:58 +00:00
|
|
|
* `Tab`
|
2014-08-04 16:00:39 +00:00
|
|
|
* `Backspace`
|
|
|
|
* `Delete`
|
|
|
|
* `Insert`
|
|
|
|
* `Return` (or `Enter` as alias)
|
|
|
|
* `Up`, `Down`, `Left` and `Right`
|
|
|
|
* `Home` and `End`
|
|
|
|
* `PageUp` and `PageDown`
|
|
|
|
* `Escape` (or `Esc` for short)
|
|
|
|
* `VolumeUp`, `VolumeDown` and `VolumeMute`
|
|
|
|
* `MediaNextTrack`, `MediaPreviousTrack`, `MediaStop` and `MediaPlayPause`
|
2016-03-06 06:12:04 +00:00
|
|
|
* `PrintScreen`
|