加速器
定義鍵盤快捷鍵。
加速器是字串,可以包含多個修飾符和單個按鍵碼,並以 +
字元組合,用於定義整個應用程式的鍵盤快捷鍵。加速器不區分大小寫。
範例
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
- 數字鍵盤÷
鍵