Skip to main content

加速器

¥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 代替 OptionOption 密钥仅存在于 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 (or Cmd for short)

  • Control(或简称 Ctrl

    ¥Control (or Ctrl for short)

  • CommandOrControl(或简称 CmdOrCtrl

    ¥CommandOrControl (or CmdOrCtrl for short)

  • Alt

  • Option

  • AltGr

  • Shift

  • Super

  • Meta

可用的键码

¥Available key codes

  • 09

    ¥0 to 9

  • AZ

    ¥A to Z

  • F1F24

    ¥F1 to F24

  • 各种标点符号:)!@#$%^&*(:;:+=<,_->.?/~、```、 {][|\}"

    ¥Various Punctuation: ), !, @, #, $, %, ^, &, *, (, :, ;, :, +, =, <, ,, _, -, >, ., ?, /, ~, `, {, ], [, |, \, }, "

  • Plus

  • Space

  • Tab

  • Capslock

  • Numlock

  • Scrolllock

  • Backspace

  • Delete

  • Insert

  • Return(或 Enter 作为别名)

    ¥Return (or Enter as alias)

  • UpDownLeftRight

    ¥Up, Down, Left and Right

  • HomeEnd

    ¥Home and End

  • PageUpPageDown

    ¥PageUp and PageDown

  • Escape(或简称 Esc

    ¥Escape (or Esc for short)

  • VolumeUpVolumeDownVolumeMute

    ¥VolumeUp, VolumeDown and VolumeMute

  • MediaNextTrackMediaPreviousTrackMediaStopMediaPlayPause

    ¥MediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause

  • 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