Global shortcuts
System-wide keyboard shortcuts (work even when the app isn't focused), flat on window.Electron for renderer-registered shortcuts, plus a static config surface for shortcuts declared up front. Source: src/main/shortcuts.ts, channel prefix shortcuts:*. Always on, no config needed to use the runtime API — static shortcuts are declared via createElectronApp()'s shortcuts option (electron/user/shortcuts.ts, scaffolded by dae init).
Static shortcuts (GlobalShortcutDef[])
Three mutually exclusive variants, registered once at startup and automatically unregistered on quit:
export type GlobalShortcutDef =
| { accelerator: string; event: string } // sends { event } to onShortcut()
| { accelerator: string; action: MainAction } // runs a built-in main-process action
| { accelerator: string; handler: () => void }; // runs arbitrary custom main-process code
// electron/user/shortcuts.ts
export const shortcuts: GlobalShortcutDef[] = [
{ accelerator: 'CmdOrCtrl+Shift+K', event: 'open-search' },
{ accelerator: 'CmdOrCtrl+Shift+H', action: 'toggleWindow' },
{ accelerator: 'CmdOrCtrl+Shift+L', handler: () => myService.doSomething() },
];
MainAction
| Value | Effect |
|---|---|
quit |
Quit the application |
minimize |
Minimize the window to the taskbar |
maximize |
Maximize the window |
toggleMaximize |
Toggle between maximized and normal state |
toggleFullscreen |
Toggle fullscreen mode |
toggleWindow |
Show + focus when hidden/minimized, hide when visible |
focus |
Show and bring the window to the front |
reload |
Reload the renderer |
openDevTools |
Open DevTools |
Renderer-side methods
| Method | Returns | Notes |
|---|---|---|
registerShortcut(accelerator: string, event: string) |
Promise<boolean> |
true if registration succeeded, false if the accelerator is already taken by another application. Fires onShortcut({ event }) when triggered. Auto-unregistered on app quit; call unregisterShortcut() to remove it earlier. |
unregisterShortcut(accelerator: string) |
Promise<void> |
|
onShortcut(callback: (data: { event: string }) => void) |
() => void (unsubscribe) |
Fires for both static (event variant) and dynamically-registered shortcuts. Not part of .safe (event subscription, never throws). |
Example
import { useEffect } from 'react';
useEffect(() => {
return window.Electron.onShortcut(({ event }) => {
if (event === 'open-search') setSearchOpen(true);
});
}, []);
await window.Electron.registerShortcut('CmdOrCtrl+K', 'open-search');
.safe
registerShortcut and unregisterShortcut are fully mirrored at window.Electron.safe.* (flat, same shape as the default surface). onShortcut has no .safe counterpart — it's a pure event subscription.