Zum Hauptteil springen

Accelerator

Definiere Tastenkürzel

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.

Beispiele:

  • CommandOrControl+A
  • CommandOrControl+Shift+Z

Tastenkürzel werden registriert mit dem globalShortcut Modul durch die register Methode, z.B.

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.
})
})

Hinweis zu Betriebssystemen

Unter Linux und Windows hat die Command Taste keinen Effekt, weshalb CommandOrControl benutzt werden sollte. Es repräsentiert Command unter macOS und Control unter Linux und Windows um Tastenkürzel zu definieren.

Verwenden Sie Alt anstelle von Option. Option existiert nur unter macOS, wohingegen Alt in allen Betriebssystemen verfügbar ist.

The Super (or Meta) key is mapped to the Windows key on Windows and Linux and Cmd on macOS.

Verfügbare Modifikatoren

  • Command (oder kurz Cmd)
  • Control (oder kurz Ctrl)
  • CommandOrControl (oder kurz CmdOrCtrl)
  • Alt
  • Option
  • AltGr
  • Shift
  • Super
  • Meta

Verfügbare Tastencodes

  • 0 bis 9
  • A bis Z
  • F1 bis F24
  • Sonderzeichen wie ~, !, @, #, $, etc.
  • Plus
  • Space (Leerzeichen)
  • Tab
  • Capslock
  • Numlock
  • Scrolllock
  • Backspace
  • Delete
  • Insert
  • Return (Oder Enter als Alias)
  • Up, Down, Left und Right
  • Home und End
  • PageUp und PageDown
  • Escape (oder Esc als Abkürzung)
  • VolumeUp, VolumeDown und VolumeMute
  • MediaNextTrack, MediaPreviousTrack, MediaStop und MediaPlayPause
  • PrintScreen
  • NumPad-Tasten
    • num0 - num9
    • numdec - decimal key
    • numadd - numpad + key
    • numsub - numpad - key
    • nummult - numpad * key
    • numdiv - numpad ÷ key