本文介绍:快捷键字符串

使用globalShortcut中的register绑定快捷键.

快捷键字符串

多个则采用 + 连接,例如:

  • CommandOrControl+A
  • CommandOrControl+Shift+Z

例子:

  1. const {app, globalShortcut} = require('electron')
  2. app.on('ready', () => {
  3. // 注册 'CommandOrControl+Y' 快捷方式监听器
  4. globalShortcut.register('CommandOrControl+Y', () => {
  5. // 按下 Y + either Command/Control后的处理
  6. })
  7. })

可用的功能键

  • Command(或缩写为 Cmd)
  • Control(或缩写为 Ctrl)
  • CommandOrControl(或缩写为 CmdOrCtrl) - Linux 和 Windows 下的 Control 键,macOS 的 Command 键。
  • Alt
  • Option
  • AltGr
  • Shift
  • Super - Linux 和 Windows 上的 Windows 键,macOS 的 Command 键。

可用的普通键

  • 09
  • AZ
  • F1F12
  • 类似 ~, !, @, #, $ 的标点符号。
  • Plus
  • Space
  • Backspace
  • Delete
  • Insert
  • Return(等同 Enter )
  • Up, Down, LeftRight
  • HomeEnd
  • PageUpPageDown
  • Escape(可缩写为 Esc)
  • VolumeUp , VolumeDownVolumeMute
  • MediaNextTrack , MediaPreviousTrack , MediaStopMediaPlayPause
  • PrintScreen