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

Function createKeyboardEvent

packages/hotkeys/tests/match.test.ts:12–42  ·  view source on GitHub ↗

* Helper to create a mock KeyboardEvent

(
  key: string,
  options: {
    ctrlKey?: boolean
    shiftKey?: boolean
    altKey?: boolean
    metaKey?: boolean
    code?: string
  } = {},
)

Source from the content-addressed store, hash-verified

10 * Helper to create a mock KeyboardEvent
11 */
12function createKeyboardEvent(
13 key: string,
14 options: {
15 ctrlKey?: boolean
16 shiftKey?: boolean
17 altKey?: boolean
18 metaKey?: boolean
19 code?: string
20 } = {},
21): KeyboardEvent {
22 // Auto-generate code for letters and digits if not provided
23 let code = options.code
24 if (code === undefined) {
25 if (key.length === 1 && /^[a-zA-Z]$/.test(key)) {
26 code = `Key${key.toUpperCase()}`
27 } else if (key.length === 1 && /^[0-9]$/.test(key)) {
28 code = `Digit${key}`
29 }
30 }
31
32 return {
33 key,
34 code,
35 ctrlKey: options.ctrlKey ?? false,
36 shiftKey: options.shiftKey ?? false,
37 altKey: options.altKey ?? false,
38 metaKey: options.metaKey ?? false,
39 preventDefault: vi.fn(),
40 stopPropagation: vi.fn(),
41 } as unknown as KeyboardEvent
42}
43
44describe('matchesKeyboardEvent', () => {
45 describe('single key matching', () => {

Callers 1

match.test.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…