Accelerator
Accelerator
Define keyboard shortcuts.
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.
Examples:
CommandOrControl+A
CommandOrControl+Shift+Z
Shortcuts are registered with the globalShortcut
module using the register
method, i.e.
const {app, globalShortcut} = require('electron') app.on('ready', () => { // Register a 'CommandOrControl+Y' shortcut listener. globalShortcut.register('CommandOrControl+Y', () => { // Do stuff when Y and either Command/Control is pressed. }) })
Platform notice
On Linux and Windows, the Command
key does not have any effect so use CommandOrControl
which represents Command
on macOS and Control
on Linux and Windows to define some accelerators.
Use Alt
instead of Option
. The Option
key only exists on macOS, whereas the Alt
key is available on all platforms.
The Super
key is mapped to the Windows
key on Windows and Linux and Cmd
on macOS.
Available modifiers
-
Command
(orCmd
for short) -
Control
(orCtrl
for short) -
CommandOrControl
(orCmdOrCtrl
for short) Alt
Option
AltGr
Shift
Super
Available key codes
-
0
to9
-
A
toZ
-
F1
toF24
- Punctuations like
~
,!
,@
,#
,$
, etc. Plus
Space
Tab
Backspace
Delete
Insert
-
Return
(orEnter
as alias) -
Up
,Down
,Left
andRight
-
Home
andEnd
-
PageUp
andPageDown
-
Escape
(orEsc
for short) -
VolumeUp
,VolumeDown
andVolumeMute
-
MediaNextTrack
,MediaPreviousTrack
,MediaStop
andMediaPlayPause
PrintScreen
© 2013–2017 GitHub Inc.
Licensed under the MIT license.
https://electron.atom.io/docs/api/accelerator/