Docs
Cloudflare
Railway
CodeRabbit
SerpAPI
WorkOS
OpenRouter
Netlify
Clerk
AG Grid
Unkey
Electric
Prisma
Sentry
Cloudflare
Railway
CodeRabbit
SerpAPI
WorkOS
OpenRouter
Netlify
Clerk
AG Grid
Unkey
Electric
Prisma
Sentry
API Reference
Hotkeys API Reference
Hotkey Sequence API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Normalization & format API Reference
Hotkeys API Reference

HotkeyManager

Class: HotkeyManager

Defined in: hotkey-manager.ts:186

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.

Example

ts
const manager = HotkeyManager.getInstance()

const unregister = manager.register('Mod+S', (event, context) => {
  console.log('Save triggered!')
})

// Later, to unregister:
unregister()
const manager = HotkeyManager.getInstance()

const unregister = manager.register('Mod+S', (event, context) => {
  console.log('Save triggered!')
})

// Later, to unregister:
unregister()

Properties

registrations

ts
readonly registrations: Store<Map<string, HotkeyRegistration>>;
readonly registrations: Store<Map<string, HotkeyRegistration>>;

Defined in: hotkey-manager.ts:208

The TanStack Store containing all hotkey registrations. Use this to subscribe to registration changes or access current registrations.

Example

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

Methods

destroy()

ts
destroy(): void;
destroy(): void;

Defined in: hotkey-manager.ts:741

Destroys the manager and removes all listeners.

Returns


getRegistrationCount()

ts
getRegistrationCount(): number;
getRegistrationCount(): number;

Defined in: hotkey-manager.ts:712

Gets the number of registered hotkeys.

Returns


isRegistered()

ts
isRegistered(hotkey, target?): boolean;
isRegistered(hotkey, target?): boolean;

Defined in: hotkey-manager.ts:723

Checks if a specific hotkey is registered.

Parameters

hotkey

The hotkey string to check

target?

Optional target element to match (if provided, both hotkey and target must match)

| |

Returns

True if a matching registration exists


register()

ts
register(
   hotkey, 
   callback, 
   options): HotkeyRegistrationHandle;
register(
   hotkey, 
   callback, 
   options): HotkeyRegistrationHandle;

Defined in: hotkey-manager.ts:271

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.

Parameters

hotkey

The hotkey string (e.g., 'Mod+S') or RawHotkey object

callback

The function to call when the hotkey is pressed

options

=

Options for the hotkey behavior

Returns

A handle for managing the registration

Example

ts
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()
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()

ts
triggerRegistration(id): boolean;
triggerRegistration(id): boolean;

Defined in: hotkey-manager.ts:676

Triggers a registration's callback programmatically from devtools. Creates a synthetic KeyboardEvent and invokes the callback.

Parameters

id

The registration ID to trigger

Returns

True if the registration was found and triggered


getInstance()

ts
static getInstance(): HotkeyManager;
static getInstance(): HotkeyManager;

Defined in: hotkey-manager.ts:229

Gets the singleton instance of HotkeyManager.

Returns


resetInstance()

ts
static resetInstance(): void;
static resetInstance(): void;

Defined in: hotkey-manager.ts:239

Resets the singleton instance. Useful for testing.

Returns