Add keyboard shortcuts locally to Electron BrowserWindow instances without using a Menu.
electron-localshortcut is a Node.js module for Electron applications that allows developers to add keyboard shortcuts scoped to individual BrowserWindow instances. It solves the problem of Electron's lack of built-in support for window-local shortcuts without relying on menu items, providing more precise control over shortcut behavior. The module automatically manages shortcut activation based on window focus state, ensuring shortcuts only work when appropriate.
Electron developers building desktop applications that require complex keyboard shortcut systems, especially those needing different shortcuts for different windows or contextual shortcut behavior.
Developers choose electron-localshortcut because it provides a simple, focused API for window-scoped keyboard shortcuts that Electron lacks natively. Unlike global shortcuts that affect the entire system, it offers precise control per window with automatic lifecycle management, making it ideal for multi-window applications.
Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The module automatically unregisters and restores shortcuts based on window focus and state, as described in the 'Shortcut behaviour' section, ensuring no interference when windows are hidden or minimized.
It allows registering shortcuts specific to individual BrowserWindows, solving Electron's limitation mentioned in the README for avoiding global shortcut issues, providing granular per-window control.
You can register multiple key combinations like ['Ctrl+R', 'F5'] to trigger the same callback, enhancing flexibility as shown in the usage example.
App shortcuts work when any app window is focused but don't affect other system applications, unlike Electron's native global shortcuts, preventing conflicts with other apps.
This module is specifically designed for Electron applications and cannot be used in other desktop frameworks, restricting its use outside the Electron ecosystem.
The README does not address handling conflicts with other shortcuts in the system or within the app, potentially leading to user frustration if shortcuts overlap.
It was built to circumvent an Electron issue, so it relies on Electron's internal behavior and may break if the underlying issue is fixed or if Electron's API changes significantly.