加速器
定义键盘快捷键。
加速器是字符串,可以包含多个修饰符和单个键代码,用 +
字符组合,并用于定义应用程序中的键盘快捷键。加速器不区分大小写。
例子
CommandOrControl+A
CommandOrControl+Shift+Z
快捷方式使用 globalShortcut
模块的 register
方法注册,例如:
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.
})
})
平台提示
在 Linux 和 Windows 上,Command
键没有任何效果,因此使用 CommandOrControl
,它代表 macOS 上的 Command
,Linux 和 Windows 上的 Control
来定义一些加速器。
使用 Alt
代替 Option
。Option
键仅存在于 macOS 上,而 Alt
键在所有平台上都可用。
Super
(或 Meta
)键映射到 Windows 上的 Windows
键和 macOS 上的 Cmd
。
可用修饰符
Command
(或简写为Cmd
)Control
(或简写为Ctrl
)CommandOrControl
(或简写为CmdOrCtrl
)Alt
Option
AltGr
Shift
Super
Meta
可用键代码
0
到9
A
到Z
F1
到F24
- 各种标点符号:
)
,!
,@
,#
,$
,%
,^
,&
,*
,(
,:
,;
,:
,+
,=
,<
,,
,_
,-
,>
,.
,?
,/
,~
,`
,{
,]
,[
,|
,\
,}
,"
Plus
Space
Tab
Capslock
Numlock
Scrolllock
Backspace
Delete
Insert
Return
(或别名Enter
)Up
,Down
,Left
和Right
Home
和End
PageUp
和PageDown
Escape
(或简写为Esc
)VolumeUp
,VolumeDown
和VolumeMute
MediaNextTrack
,MediaPreviousTrack
,MediaStop
和MediaPlayPause
PrintScreen
- 数字键盘按键
num0
-num9
numdec
- 小数键numadd
- 数字键盘+
键numsub
- 数字键盘-
键nummult
- 数字键盘*
键numdiv
- 数字键盘÷
键