加速器
¥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. Accelerators are case insensitive.
示例:
¥Examples:
-
CommandOrControl+A
-
CommandOrControl+Shift+Z
快捷方式使用 register
方法注册到 globalShortcut
模块,即
¥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
在 Linux 和 Windows 上,Command
键没有任何作用,因此使用 CommandOrControl
(在 macOS 上代表 Command
)以及在 Linux 和 Windows 上代表 Control
来定义一些加速器。
¥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.
使用 Alt
代替 Option
。Option
密钥仅存在于 macOS 上,而 Alt
密钥在所有平台上都可用。
¥Use Alt
instead of Option
. The Option
key only exists on macOS, whereas
the Alt
key is available on all platforms.
Super
(或 Meta
)键映射到 Windows 和 Linux 上的 Windows
键,以及 macOS 上的 Cmd
键。
¥The Super
(or Meta
) key is mapped to the Windows
key on Windows and Linux and
Cmd
on macOS.
可用修饰符
¥Available modifiers
-
Command
(或简称Cmd
)¥
Command
(orCmd
for short) -
Control
(或简称Ctrl
)¥
Control
(orCtrl
for short) -
CommandOrControl
(或简称CmdOrCtrl
)¥
CommandOrControl
(orCmdOrCtrl
for short) -
Alt
-
Option
-
AltGr
-
Shift
-
Super
-
Meta
可用的键码
¥Available key codes
-
0
至9
¥
0
to9
-
A
至Z
¥
A
toZ
-
F1
至F24
¥
F1
toF24
-
各种标点符号:
)
、!
、@
、#
、$
、%
、^
、&
、*
、(
、:
、;
、:
、+
、=
、<
、,
、_
、-
、>
、.
、?
、/
、~
、```、{
、]
、[
、|
、\
、}
、"
¥Various Punctuation:
)
,!
,@
,#
,$
,%
,^
,&
,*
,(
,:
,;
,:
,+
,=
,<
,,
,_
,-
,>
,.
,?
,/
,~
,`
,{
,]
,[
,|
,\
,}
,"
-
Plus
-
Space
-
Tab
-
Capslock
-
Numlock
-
Scrolllock
-
Backspace
-
Delete
-
Insert
-
Return
(或Enter
作为别名)¥
Return
(orEnter
as alias) -
Up
、Down
、Left
和Right
¥
Up
,Down
,Left
andRight
-
Home
和End
¥
Home
andEnd
-
PageUp
和PageDown
¥
PageUp
andPageDown
-
Escape
(或简称Esc
)¥
Escape
(orEsc
for short) -
VolumeUp
、VolumeDown
和VolumeMute
¥
VolumeUp
,VolumeDown
andVolumeMute
-
MediaNextTrack
、MediaPreviousTrack
、MediaStop
和MediaPlayPause
¥
MediaNextTrack
,MediaPreviousTrack
,MediaStop
andMediaPlayPause
-
PrintScreen
-
数字键盘按键
¥NumPad Keys
-
num0
-num9
-
numdec
- 小数键¥
numdec
- decimal key -
numadd
- 数字键盘+
键¥
numadd
- numpad+
key -
numsub
- 数字键盘-
键¥
numsub
- numpad-
key -
nummult
- 数字键盘*
键¥
nummult
- numpad*
key -
numdiv
- 数字键盘÷
键¥
numdiv
- numpad÷
key
-