Defined in: hotkey-manager.ts:156
Singleton manager for hotkey registrations.
This class provides a centralized way to register and manage keyboard hotkeys. It uses a single event listener for efficiency, regardless of how many hotkeys are registered.
const manager = HotkeyManager.getInstance()
const unregister = manager.register('Mod+S', (event, context) => {
console.log('Save triggered!')
})
// Later, to unregister:
unregister()
readonly registrations: Store<Map<string, HotkeyRegistration>>;
Defined in: hotkey-manager.ts:178
The TanStack Store containing all hotkey registrations. Use this to subscribe to registration changes or access current registrations.
const manager = HotkeyManager.getInstance()
// Subscribe to registration changes
const unsubscribe = manager.registrations.subscribe(() => {
console.log('Registrations changed:', manager.registrations.state.size)
})
// Access current registrations
for (const [id, reg] of manager.registrations.state) {
console.log(reg.hotkey, reg.options.enabled)
}
destroy(): void;
Defined in: hotkey-manager.ts:780
Destroys the manager and removes all listeners.
void
getRegistrationCount(): number;
Defined in: hotkey-manager.ts:751
Gets the number of registered hotkeys.
number
isRegistered(hotkey, target?): boolean;
Defined in: hotkey-manager.ts:762
Checks if a specific hotkey is registered.
The hotkey string to check
Optional target element to match (if provided, both hotkey and target must match)
Document | Window | HTMLElement
boolean
True if a matching registration exists
register(
hotkey,
callback,
options): HotkeyRegistrationHandle;
Defined in: hotkey-manager.ts:241
Registers a hotkey handler and returns a handle for updating the registration.
The returned handle allows updating the callback and options without re-registering, which is useful for avoiding stale closures in React.
The hotkey string (e.g., 'Mod+S') or RawHotkey object
The function to call when the hotkey is pressed
HotkeyOptions = {}
Options for the hotkey behavior
A handle for managing the registration
const handle = manager.register('Mod+S', callback)
// Update callback without re-registering (avoids stale closures)
handle.callback = newCallback
// Update options
handle.setOptions({ enabled: false })
// Unregister when done
handle.unregister()
triggerRegistration(id): boolean;
Defined in: hotkey-manager.ts:715
Triggers a registration's callback programmatically from devtools. Creates a synthetic KeyboardEvent and invokes the callback.
string
The registration ID to trigger
boolean
True if the registration was found and triggered
static getInstance(): HotkeyManager;
Defined in: hotkey-manager.ts:199
Gets the singleton instance of HotkeyManager.
HotkeyManager
static resetInstance(): void;
Defined in: hotkey-manager.ts:209
Resets the singleton instance. Useful for testing.
void