← All @molecule/* packages · App templates
@molecule/app-keyboard-shortcuts-hotkeysProvider bond · keyboard-shortcuts · App (browser) · v1.0.1 · Apache-2.0
In-memory shortcut registry for @molecule/app-keyboard-shortcuts (app owns the keydown listener and dispatch)
npm install @molecule/app-keyboard-shortcuts-hotkeysnpm · Source on GitHub · Implements @molecule/app-keyboard-shortcuts
@molecule/app-keyboard-shortcuts-hotkeys is a provider bond on the app (browser) side: it implements the keyboard-shortcuts core interface (@molecule/app-keyboard-shortcuts) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { provider } from '@molecule/app-keyboard-shortcuts-hotkeys'
import { setProvider } from '@molecule/app-keyboard-shortcuts'
setProvider(provider) // once, at app startup (bonds.ts)
const unregister = provider.register({
keys: 'ctrl+s',
handler: () => save(), // fires on Ctrl+S; preventDefault is automatic
description: 'Save document',
})
// ...later, when the owning screen unmounts:
unregister()Works with: @molecule/app-keyboard-shortcuts
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Keyboard-shortcuts provider for @molecule/app-keyboard-shortcuts, backed by
the hotkeys-js library. This bond attaches real global key listeners:
a registered Shortcut.handler fires on the actual keypress.
import { provider } from '@molecule/app-keyboard-shortcuts-hotkeys'
import { setProvider } from '@molecule/app-keyboard-shortcuts'
setProvider(provider) // once, at app startup (bonds.ts)
const unregister = provider.register({
keys: 'ctrl+s',
handler: () => save(), // fires on Ctrl+S; preventDefault is automatic
description: 'Save document',
})
// ...later, when the owning screen unmounts:
unregister()
provider
npm install @molecule/app-keyboard-shortcuts-hotkeys @molecule/app-keyboard-shortcuts hotkeys-js
HotkeysConfigProvider-specific configuration options.
interface HotkeysConfig {
/**
* hotkeys-js scope assigned to shortcuts registered without their own
* `scope`, and set as the active scope when the provider is created. Defaults
* to `'all'` (shortcuts under `'all'` fire regardless of the active scope).
*/
defaultScope?: string
/** Whether shortcuts are enabled initially. Defaults to `true`. */
enabled?: boolean
}
createProvider(config)Creates a hotkeys-js-backed keyboard shortcuts provider.
The returned provider binds every registered shortcut to hotkeys-js, so
handlers fire on real key events (the bug this bond previously had was that it
stored shortcuts in a Map but never attached a listener). hotkeys-js's default
filter suppresses firing while an input/textarea/select/contenteditable is
focused.
function createProvider(config?: HotkeysConfig): KeyboardShortcutsProvider
config — Optional provider configuration.Returns: A configured KeyboardShortcutsProvider whose handlers fire on keypress.
providerDefault hotkeys-js keyboard shortcuts provider instance.
const provider: KeyboardShortcutsProvider
Implements @molecule/app-keyboard-shortcuts interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/app-keyboard-shortcuts'
import { provider } from '@molecule/app-keyboard-shortcuts-hotkeys'
export function setupKeyboardShortcutsHotkeys(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/app-keyboard-shortcuts ^1.0.1@molecule/app-keyboard-shortcuts
hotkeys-js
Handlers fire for real. register() binds via hotkeys(combo, handler);
pressing the combo invokes Shortcut.handler with the real KeyboardEvent.
event.preventDefault() is called automatically unless
Shortcut.preventDefault === false — so a combo that collides with a browser
default (Ctrl+S, Ctrl+P) suppresses the browser action.
Input guard is built in. hotkeys-js's default filter does not fire while
an input/textarea/select/contenteditable is focused, so typing never
triggers shortcuts unless you opt in.
Scopes. A Shortcut.scope binds under that hotkeys-js scope and fires
only while that scope is active. Shortcuts with no scope bind under
HotkeysConfig.defaultScope (default 'all', which fires regardless of the
active scope). The active scope is set from defaultScope at provider
creation; the core interface exposes no runtime scope switch, so drive
scoping through defaultScope + per-shortcut scope.
enable()/disable() gate whether bound handlers run (the bindings stay
attached, just suppressed). getAll() reflects the resulting enabled
state; isPressed(key) reflects hotkeys-js's live key-state tracking.
Wire it with setProvider() from @molecule/app-keyboard-shortcuts or
bond('keyboard-shortcuts', provider) from @molecule/app-bond — both route
through the shared registry.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip: