MCPcopy Create free account
hub / github.com/TanStack/hotkeys / triggerSequence

Method triggerSequence

packages/hotkeys/src/sequence-manager.ts:588–626  ·  view source on GitHub ↗

* Triggers a sequence's callback programmatically from devtools. * Creates a synthetic KeyboardEvent from the last key in the sequence. * * @param id - The registration ID to trigger * @returns True if the registration was found and triggered

(id: string)

Source from the content-addressed store, hash-verified

586 * @returns True if the registration was found and triggered
587 */
588 triggerSequence(id: string): boolean {
589 const registration = this.#registrations.get(id)
590 if (!registration) {
591 return false
592 }
593
594 const lastParsed =
595 registration.parsedSequence[registration.parsedSequence.length - 1]
596 if (!lastParsed) {
597 return false
598 }
599
600 const syntheticEvent = new KeyboardEvent(
601 registration.options.eventType ?? 'keydown',
602 {
603 key: lastParsed.key,
604 ctrlKey: lastParsed.ctrl,
605 shiftKey: lastParsed.shift,
606 altKey: lastParsed.alt,
607 metaKey: lastParsed.meta,
608 bubbles: true,
609 cancelable: true,
610 },
611 )
612
613 registration.triggerCount++
614 registration.hasFired = true
615
616 this.#syncRegistrationView(registration)
617
618 const context: HotkeyCallbackContext = {
619 hotkey: registration.sequence.join(' ') as Hotkey,
620 parsedHotkey: lastParsed,
621 }
622
623 registration.callback(syntheticEvent, context)
624
625 return true
626 }
627
628 /**
629 * Gets the number of registered sequences.

Callers 2

handleTriggerFunction · 0.80

Calls 2

#syncRegistrationViewMethod · 0.95
callbackMethod · 0.45

Tested by

no test coverage detected