快捷键标识符
定义键盘快捷键。
快捷键标识符(Accelerator)是字符串,可以包含多个修饰符和一个键代码,它们通过 +
字符组合在一起,用于在整个应用程序中定义键盘快捷键。 快捷键标识符不区分大小写。
示例
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 和 Linux 上映射到 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
- 数字小键盘÷
键