跳到主内容

快捷键标识符

定义键盘快捷键。

快捷键标识符(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 而不是 OptionOption 键仅存在于 macOS 上,而 Alt 键在所有平台上都可用。

Super (或简称 Meta) 键在 Windows 和 Linux 上映射到 Windows 键,在 macOS 上映射到 Cmd

可用修饰符

  • Command (或简称 Cmd)
  • Control (或简称 Ctrl)
  • CommandOrControl (或简称 CmdOrCtrl)
  • Alt
  • Option
  • AltGr
  • Shift
  • Super
  • Meta

可用键代码

  • 09
  • AZ
  • F1F24
  • 各种标点符号:), !, @, #, $, %, ^, &, *, (, :, ;, :, +, =, <, ,, _, -, >, ., ?, /, ~, `, {, ], [, |, \, }, "
  • Plus
  • Space
  • Tab
  • Capslock
  • Numlock
  • Scrolllock
  • Backspace
  • Delete
  • Insert
  • Return (或别名 Enter)
  • Up, Down, LeftRight
  • HomeEnd
  • PageUpPageDown
  • Escape (或简称 Esc)
  • VolumeUp, VolumeDownVolumeMute
  • MediaNextTrack, MediaPreviousTrack, MediaStopMediaPlayPause
  • PrintScreen
  • 数字小键盘按键
    • num0 - num9
    • numdec - 小数点键
    • numadd - 数字小键盘 +
    • numsub - 数字小键盘 -
    • nummult - 数字小键盘 *
    • numdiv - 数字小键盘 ÷