Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
API Reference
Hotkeys API Reference
Hotkey Sequence API Reference
Key Hold API Reference
Held Keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Format for Display API Reference
Hotkeys API Reference

HotkeyManager

Class: HotkeyManager

Defined in: hotkey-manager.ts:144

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

Properties

registrations

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

Defined in: hotkey-manager.ts:166

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

Methods

destroy()

ts
destroy(): void;

Defined in: hotkey-manager.ts:702

Destroys the manager and removes all listeners.

Returns

void


getRegistrationCount()

ts
getRegistrationCount(): number;

Defined in: hotkey-manager.ts:673

Gets the number of registered hotkeys.

Returns

number


isRegistered()

ts
isRegistered(hotkey, target?): boolean;

Defined in: hotkey-manager.ts:684

Checks if a specific hotkey is registered.

Parameters

hotkey

Hotkey

The hotkey string to check

target?

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

HTMLElement | Document | Window

Returns

boolean

True if a matching registration exists


register()

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

Defined in: hotkey-manager.ts:229

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

RegisterableHotkey

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

callback

HotkeyCallback

The function to call when the hotkey is pressed

options

HotkeyOptions = {}

Options for the hotkey behavior

Returns

HotkeyRegistrationHandle

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

triggerRegistration()

ts
triggerRegistration(id): boolean;

Defined in: hotkey-manager.ts:637

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

Parameters

id

string

The registration ID to trigger

Returns

boolean

True if the registration was found and triggered


getInstance()

ts
static getInstance(): HotkeyManager;

Defined in: hotkey-manager.ts:187

Gets the singleton instance of HotkeyManager.

Returns

HotkeyManager


resetInstance()

ts
static resetInstance(): void;

Defined in: hotkey-manager.ts:197

Resets the singleton instance. Useful for testing.

Returns

void