本页还没有译文
本页 53 段还没译成Français,下面显示的是英文原文。HotkeyRecorder
还没翻译译自英文(tanstack.com)本页 53 段都还没译
Defined in: hotkey-recorder.ts:94
Framework-agnostic class for recording keyboard shortcuts.
This class handles all the complexity of capturing keyboard events, converting them to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete to clear.
State Management:
- Uses TanStack Store for reactive state management
- State can be accessed via
recorder.store.statewhen using the class directly - When using framework adapters (React), use
useSelectorhooks for reactive state
Example
const recorder = new HotkeyRecorder({
onRecord: (hotkey) => {
console.log('Recorded:', hotkey)
},
onCancel: () => {
console.log('Recording cancelled')
},
})
// Start recording
recorder.start()
// Access state directly
console.log(recorder.store.state.isRecording) // true
// Subscribe to changes with TanStack Store
const unsubscribe = recorder.store.subscribe(() => {
console.log('Recording:', recorder.store.state.isRecording)
})
// Cleanup
recorder.destroy()
unsubscribe()Constructors
Constructor
new HotkeyRecorder(options): HotkeyRecorder;Defined in: hotkey-recorder.ts:119
Options may be a getter to read current configuration during an active session.
Parameters
options
| HotkeyRecorderOptions
| (() => HotkeyRecorderOptions)
Returns
HotkeyRecorder
Properties
store
readonly store: Store<HotkeyRecorderState>;Defined in: hotkey-recorder.ts:99
The TanStack Store instance containing the recorder state. Use this to subscribe to state changes or access current state.
Methods
cancel()
cancel(): void;Defined in: hotkey-recorder.ts:302
Cancel recording without saving.
Removes the event listener, resets the recording state, and calls the onCancel callback if provided.
Returns
void
destroy()
destroy(): void;Defined in: hotkey-recorder.ts:348
Clean up event listeners and reset state.
Call this when you're done with the recorder to ensure all event listeners are properly removed.
Returns
void
setOptions()
setOptions(options): void;Defined in: hotkey-recorder.ts:128
Updates the recorder options, including callbacks. This allows framework adapters to sync callback changes without recreating the recorder.
Parameters
options
Partial<HotkeyRecorderOptions>
Returns
void
start()
start(): void;Defined in: hotkey-recorder.ts:139
Start recording a new hotkey.
Sets up a keydown event listener that captures keyboard events and converts them to hotkey strings. Recording continues until a valid hotkey is recorded, Escape is pressed, or stop/cancel is called.
Returns
void
stop()
stop(): void;Defined in: hotkey-recorder.ts:281
Stop recording (same as cancel, but doesn't call onCancel).
Removes the event listener and resets the recording state.
Returns
void