IOverlayHotkey
Electron APIs / overlay / IOverlayHotkey
Represents an overlay hotkey configuration.
Defines:
- Unique name.
- Main keycode.
- Optional modifier keys.
- Passthrough behavior.
Example
const screenshotHotkey: IOverlayHotkey = {
name: "take-screenshot",
keyCode: 80, // p
modifiers: { ctrl: true, alt: true },
passthrough: false,
};
// Since 1.13.3: use W3C KeyboardEvent.code strings (preferred, layout-independent)
const toggleHotkey: IOverlayHotkey = {
name: "toggle",
keyCode: "KeyF",
modifiers: { ctrl: true, custom: "Tab" },
passthrough: true,
};
Properties
| Property | Type | Description |
|---|---|---|
keyCode | string | number | Primary key code for the hotkey. Accepts a numeric Windows Virtual-Key (VK) code or a W3C KeyboardEvent.code string (e.g. 'KeyF', 'F10', 'ArrowUp'). Remarks Numeric VK codes are layout-dependent — the same physical key produces a different VK number on non-QWERTY keyboards. Passing a KeyboardEvent.code string identifies the physical key unambiguously regardless of the user's keyboard layout. String values are resolved to VK codes at registration time. An unrecognized string throws immediately so misconfigured hotkeys are caught early. Supported string codes include: KeyA–KeyZ, Digit0–Digit9, F1–F24, Numpad0–Numpad9, ArrowUp/Down/Left/Right, Tab, Enter, Space, Backspace, Delete, Escape, Home, End, PageUp, PageDown, ShiftLeft/Right, ControlLeft/Right, AltLeft/Right, Backquote, Minus, Equal, BracketLeft/Right, Semicolon, Quote, Comma, Period, Slash, Backslash, and media/browser/launch keys. Throws Error('Unknown hotkey code: "<value>". Pass a valid KeyboardEvent.code string…') thrown at registration time when the string does not map to a known VK code. Validate the string before calling register if the value comes from user input. Example // Preferred: physical key position, layout-independent api.hotkeys.register({ name: 'toggle', keyCode: 'KeyF' }, callback); // With modifier using string code api.hotkeys.register({ name: 'screenshot', keyCode: 'KeyP', modifiers: { ctrl: true } }, callback); // Legacy: numeric VK code (still valid) api.hotkeys.register({ name: 'toggle-legacy', keyCode: 70 }, callback); // Throws at registration — unknown string api.hotkeys.register({ name: 'bad', keyCode: 'Bogus' }, callback); // Error: Unknown hotkey code: "Bogus". Pass a valid KeyboardEvent.code string… |
modifiers? | object | Modifier keys that must be pressed along with the main key. |
modifiers.alt? | boolean | Used for alt key. |
modifiers.ctrl? | boolean | Used for ctrl key. |
modifiers.custom? | string | number | Custom key binding. Accepts a numeric Windows Virtual-Key code or, since 1.13.3, a W3C KeyboardEvent.code string (same format as keyCode). |
modifiers.meta? | boolean | Use for the windows or command key. |
modifiers.shift? | boolean | Used for shift key. |
name | string | Unique name of the hotkey. |
passthrough? | boolean | Controls whether the hotkey will be passed through to the underlying game. - If true, the hotkey will be captured by the overlay and pass to the game. - If false, the hotkey will be captured exclusively by the overlay. Default false |