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+A
- CommandOrControl+Shift+Z
Shortcuts are registered with the globalShortcut module using the register method, i.e.快捷方式使用register方法在globalShortcutt模块中注册,即。
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 在Linux和Windows上,Command键没有任何作用,因此使用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.CommandOrControl来定义一些加速器,CommandOrControl在macOS上代表Command,在Linux和Windows上代表Control。
Use 使用Alt而不是Option。Alt instead of Option. The Option键仅存在于macOS上,而Alt键在所有平台上都可用。Option key only exists on macOS, whereas the Alt key is available on all platforms.
The Super(或Meta)键在Windows和Linux上映射到Windows键,在macOS上映射到Cmd。Super (or Meta) key is mapped to the Windows key on Windows and Linux and Cmd on macOS.
Available modifiers可用的修饰符
- Command(or- Cmdfor short)
- Control(or- Ctrlfor short)
- CommandOrControl(or- CmdOrCtrlfor short)
- Alt
- Option
- AltGr
- Shift
- Super
- Meta
Available key codes
- 0to- 9
- Ato- Z
- F1to- F24
- Punctuation like ~,!,@,#,$, etc.
- Plus
- Space
- Tab
- Capslock
- Numlock
- Scrolllock
- Backspace
- Delete
- Insert
- Return(or- Enteras alias)
- Up,- Down,- Leftand- Right
- Homeand- End
- PageUpand- PageDown
- Escape(or- Escfor short)
- VolumeUp,- VolumeDownand- VolumeMute
- MediaNextTrack,- MediaPreviousTrack,- MediaStopand- MediaPlayPause
- PrintScreen
- NumPad Keys- num0-- num9
- numdec- decimal key
- numadd- numpad- +key
- numsub- numpad- -key
- nummult- numpad- *key
- numdiv- numpad- ÷key