* docs: add references to app.whenReady() in isReady
* refactor: prefer app.whenReady()
In the docs, specs, and lib, replace instances of `app.once('ready')`
(seen occasionally) and `app.on('ready')` (extremely common) with
`app.whenReady()`.
It's better to encourage users to use whenReady():
1. it handles the edge case of registering for 'ready' after it's fired
2. it avoids the minor wart of leaving an active listener alive for
an event that wll never fire again
2 KiB
2 KiB
Accelerator
Define keyboard shortcuts.
Accelerators are Strings that can contain multiple modifiers and a single key code,
combined by the + character, and are used to define keyboard shortcuts
throughout your application.
Examples:
CommandOrControl+ACommandOrControl+Shift+Z
Shortcuts are registered with the globalShortcut module
using the register
method, i.e.
const { app, globalShortcut } = require('electron')
app.whenReady().then(() => {
// 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(orCmdfor short)Control(orCtrlfor short)CommandOrControl(orCmdOrCtrlfor short)AltOptionAltGrShiftSuper
Available key codes
0to9AtoZF1toF24- Punctuations like
~,!,@,#,$, etc. PlusSpaceTabCapslockNumlockScrolllockBackspaceDeleteInsertReturn(orEnteras alias)Up,Down,LeftandRightHomeandEndPageUpandPageDownEscape(orEscfor short)VolumeUp,VolumeDownandVolumeMuteMediaNextTrack,MediaPreviousTrack,MediaStopandMediaPlayPausePrintScreen- NumPad Keys
num0-num9numdec- decimal keynumadd- numpad+keynumsub- numpad-keynummult- numpad*keynumdiv- numpad÷key