@tanstack/hotkeys 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_event-target.js +1 -2
- package/dist/_keyboard-event.js +1 -2
- package/dist/_match.js +1 -2
- package/dist/_named-keys.d.ts +3 -5
- package/dist/_named-keys.js +1 -2
- package/dist/_recorder-chord.js +1 -2
- package/dist/_recording-guard.js +1 -2
- package/dist/_registration.js +1 -2
- package/dist/conflicts.d.ts +4 -7
- package/dist/conflicts.js +1 -2
- package/dist/constants.d.ts +14 -17
- package/dist/constants.js +8 -9
- package/dist/display-labels.d.ts +7 -10
- package/dist/display-labels.js +1 -2
- package/dist/format.d.ts +9 -12
- package/dist/format.js +9 -7
- package/dist/hint.d.ts +3 -6
- package/dist/hint.js +1 -2
- package/dist/hotkey-manager.d.ts +8 -10
- package/dist/hotkey-manager.js +21 -3
- package/dist/hotkey-recorder.d.ts +4 -7
- package/dist/hotkey-recorder.js +9 -6
- package/dist/hotkey-sequence-recorder.d.ts +5 -8
- package/dist/hotkey-sequence-recorder.js +6 -7
- package/dist/hotkey.types.d.ts +15 -18
- package/dist/key-state-tracker.d.ts +4 -7
- package/dist/key-state-tracker.js +6 -3
- package/dist/key.types.d.ts +17 -20
- package/dist/match.d.ts +8 -11
- package/dist/match.js +1 -2
- package/dist/parse.d.ts +11 -14
- package/dist/parse.js +5 -4
- package/dist/platform.d.ts +3 -6
- package/dist/platform.js +1 -2
- package/dist/recorder-options.d.ts +6 -9
- package/dist/sequence-manager.d.ts +11 -14
- package/dist/sequence-manager.js +12 -7
- package/dist/validate.d.ts +5 -8
- package/dist/validate.js +1 -2
- package/package.json +8 -13
- package/dist/_event-target.cjs +0 -73
- package/dist/_event-target.cjs.map +0 -1
- package/dist/_event-target.js.map +0 -1
- package/dist/_keyboard-event.cjs +0 -83
- package/dist/_keyboard-event.cjs.map +0 -1
- package/dist/_keyboard-event.js.map +0 -1
- package/dist/_match.cjs +0 -49
- package/dist/_match.cjs.map +0 -1
- package/dist/_match.js.map +0 -1
- package/dist/_named-keys.cjs +0 -68
- package/dist/_named-keys.cjs.map +0 -1
- package/dist/_named-keys.d.cts +0 -8
- package/dist/_named-keys.js.map +0 -1
- package/dist/_recorder-chord.cjs +0 -44
- package/dist/_recorder-chord.cjs.map +0 -1
- package/dist/_recorder-chord.js.map +0 -1
- package/dist/_recording-guard.cjs +0 -59
- package/dist/_recording-guard.cjs.map +0 -1
- package/dist/_recording-guard.js.map +0 -1
- package/dist/_registration.cjs +0 -54
- package/dist/_registration.cjs.map +0 -1
- package/dist/_registration.js.map +0 -1
- package/dist/conflicts.cjs +0 -55
- package/dist/conflicts.cjs.map +0 -1
- package/dist/conflicts.d.cts +0 -39
- package/dist/conflicts.js.map +0 -1
- package/dist/constants.cjs +0 -410
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -165
- package/dist/constants.js.map +0 -1
- package/dist/display-labels.cjs +0 -119
- package/dist/display-labels.cjs.map +0 -1
- package/dist/display-labels.d.cts +0 -93
- package/dist/display-labels.js.map +0 -1
- package/dist/format.cjs +0 -85
- package/dist/format.cjs.map +0 -1
- package/dist/format.d.cts +0 -99
- package/dist/format.js.map +0 -1
- package/dist/hint.cjs +0 -24
- package/dist/hint.cjs.map +0 -1
- package/dist/hint.d.cts +0 -23
- package/dist/hint.js.map +0 -1
- package/dist/hotkey-manager.cjs +0 -414
- package/dist/hotkey-manager.cjs.map +0 -1
- package/dist/hotkey-manager.d.cts +0 -234
- package/dist/hotkey-manager.js.map +0 -1
- package/dist/hotkey-recorder.cjs +0 -235
- package/dist/hotkey-recorder.cjs.map +0 -1
- package/dist/hotkey-recorder.d.cts +0 -119
- package/dist/hotkey-recorder.js.map +0 -1
- package/dist/hotkey-sequence-recorder.cjs +0 -255
- package/dist/hotkey-sequence-recorder.cjs.map +0 -1
- package/dist/hotkey-sequence-recorder.d.cts +0 -86
- package/dist/hotkey-sequence-recorder.js.map +0 -1
- package/dist/hotkey.types.d.cts +0 -236
- package/dist/index.cjs +0 -71
- package/dist/index.d.cts +0 -18
- package/dist/key-state-tracker.cjs +0 -197
- package/dist/key-state-tracker.cjs.map +0 -1
- package/dist/key-state-tracker.d.cts +0 -107
- package/dist/key-state-tracker.js.map +0 -1
- package/dist/key.types.d.cts +0 -82
- package/dist/match.cjs +0 -144
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -101
- package/dist/match.js.map +0 -1
- package/dist/parse.cjs +0 -245
- package/dist/parse.cjs.map +0 -1
- package/dist/parse.d.cts +0 -134
- package/dist/parse.js.map +0 -1
- package/dist/platform.cjs +0 -55
- package/dist/platform.cjs.map +0 -1
- package/dist/platform.d.cts +0 -44
- package/dist/platform.js.map +0 -1
- package/dist/recorder-options.d.cts +0 -34
- package/dist/sequence-manager.cjs +0 -441
- package/dist/sequence-manager.cjs.map +0 -1
- package/dist/sequence-manager.d.cts +0 -172
- package/dist/sequence-manager.js.map +0 -1
- package/dist/validate.cjs +0 -112
- package/dist/validate.cjs.map +0 -1
- package/dist/validate.d.cts +0 -67
- package/dist/validate.js.map +0 -1
- package/src/_event-target.ts +0 -157
- package/src/_keyboard-event.ts +0 -101
- package/src/_match.ts +0 -96
- package/src/_named-keys.ts +0 -62
- package/src/_recorder-chord.ts +0 -76
- package/src/_recording-guard.ts +0 -63
- package/src/_registration.ts +0 -79
- package/src/conflicts.ts +0 -125
- package/src/constants.ts +0 -455
- package/src/display-labels.ts +0 -123
- package/src/format.ts +0 -201
- package/src/hint.ts +0 -42
- package/src/hotkey-manager.ts +0 -814
- package/src/hotkey-recorder.ts +0 -348
- package/src/hotkey-sequence-recorder.ts +0 -410
- package/src/hotkey.types.ts +0 -269
- package/src/index.ts +0 -17
- package/src/key-state-tracker.ts +0 -261
- package/src/key.types.ts +0 -268
- package/src/match.ts +0 -210
- package/src/parse.ts +0 -369
- package/src/platform.ts +0 -66
- package/src/recorder-options.ts +0 -34
- package/src/sequence-manager.ts +0 -769
- package/src/validate.ts +0 -179
package/src/key-state-tracker.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { Store } from '@tanstack/store'
|
|
2
|
-
import { MODIFIER_KEYS, normalizeKeyName } from './constants'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* State interface for the KeyStateTracker.
|
|
6
|
-
*/
|
|
7
|
-
export interface KeyStateTrackerState {
|
|
8
|
-
/**
|
|
9
|
-
* Array of currently held key names (normalized, e.g. "Control", "A").
|
|
10
|
-
*/
|
|
11
|
-
heldKeys: Array<string>
|
|
12
|
-
/**
|
|
13
|
-
* Map from normalized key name to the physical `event.code` (e.g. "KeyA", "ShiftLeft").
|
|
14
|
-
* Useful for debugging which physical key was pressed.
|
|
15
|
-
*/
|
|
16
|
-
heldCodes: Record<string, string>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the default state for KeyStateTracker.
|
|
21
|
-
*/
|
|
22
|
-
function getDefaultKeyStateTrackerState(): KeyStateTrackerState {
|
|
23
|
-
return {
|
|
24
|
-
heldKeys: [],
|
|
25
|
-
heldCodes: {},
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Singleton tracker for currently held keyboard keys.
|
|
31
|
-
*
|
|
32
|
-
* This class maintains a list of all keys currently being pressed,
|
|
33
|
-
* which is useful for:
|
|
34
|
-
* - Displaying currently held keys to users
|
|
35
|
-
* - Custom shortcut recording for rebinding
|
|
36
|
-
* - Complex chord detection
|
|
37
|
-
*
|
|
38
|
-
* State Management:
|
|
39
|
-
* - Uses TanStack Store for reactive state management
|
|
40
|
-
* - State can be accessed via `tracker.store.state` when using the class directly
|
|
41
|
-
* - When using framework adapters (React), use `useHeldKeys` and `useHeldKeyCodes` hooks for reactive state
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const tracker = KeyStateTracker.getInstance()
|
|
46
|
-
*
|
|
47
|
-
* // Access state directly
|
|
48
|
-
* console.log(tracker.store.state.heldKeys) // ['Control', 'Shift']
|
|
49
|
-
*
|
|
50
|
-
* // Subscribe to changes with TanStack Store
|
|
51
|
-
* const unsubscribe = tracker.store.subscribe(() => {
|
|
52
|
-
* console.log('Currently held:', tracker.store.state.heldKeys)
|
|
53
|
-
* })
|
|
54
|
-
*
|
|
55
|
-
* // Check current state
|
|
56
|
-
* console.log(tracker.getHeldKeys()) // ['Control', 'Shift']
|
|
57
|
-
* console.log(tracker.isKeyHeld('Control')) // true
|
|
58
|
-
*
|
|
59
|
-
* // Cleanup
|
|
60
|
-
* unsubscribe()
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export class KeyStateTracker {
|
|
64
|
-
static #instance: KeyStateTracker | null = null
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The TanStack Store instance containing the tracker state.
|
|
68
|
-
* Use this to subscribe to state changes or access current state.
|
|
69
|
-
*/
|
|
70
|
-
readonly store: Store<KeyStateTrackerState> = new Store(
|
|
71
|
-
getDefaultKeyStateTrackerState(),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
#heldEntries: Map<string, { key: string; code: string }> = new Map()
|
|
75
|
-
#keydownListener: ((event: KeyboardEvent) => void) | null = null
|
|
76
|
-
#keyupListener: ((event: KeyboardEvent) => void) | null = null
|
|
77
|
-
#blurListener: (() => void) | null = null
|
|
78
|
-
|
|
79
|
-
private constructor() {
|
|
80
|
-
this.#setupListeners()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Gets the singleton instance of KeyStateTracker.
|
|
85
|
-
*/
|
|
86
|
-
static getInstance(): KeyStateTracker {
|
|
87
|
-
if (!KeyStateTracker.#instance) {
|
|
88
|
-
KeyStateTracker.#instance = new KeyStateTracker()
|
|
89
|
-
}
|
|
90
|
-
return KeyStateTracker.#instance
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Resets the singleton instance. Useful for testing.
|
|
95
|
-
*/
|
|
96
|
-
static resetInstance(): void {
|
|
97
|
-
if (KeyStateTracker.#instance) {
|
|
98
|
-
KeyStateTracker.#instance.destroy()
|
|
99
|
-
KeyStateTracker.#instance = null
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Sets up the keyboard event listeners.
|
|
105
|
-
*/
|
|
106
|
-
#setupListeners(): void {
|
|
107
|
-
if (typeof document === 'undefined') {
|
|
108
|
-
return // SSR safety
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
this.#keydownListener = (event: KeyboardEvent) => {
|
|
112
|
-
const key = normalizeKeyName(event.key)
|
|
113
|
-
const identity = event.code || `key:${key}`
|
|
114
|
-
if (!this.#heldEntries.has(identity)) {
|
|
115
|
-
this.#heldEntries.set(identity, { key, code: event.code })
|
|
116
|
-
this.#syncState()
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.#keyupListener = (event: KeyboardEvent) => {
|
|
121
|
-
const key = normalizeKeyName(event.key)
|
|
122
|
-
const identity = event.code || `key:${key}`
|
|
123
|
-
this.#heldEntries.delete(identity)
|
|
124
|
-
|
|
125
|
-
// Code-less keyup events can only be paired by their logical key.
|
|
126
|
-
if (!event.code) {
|
|
127
|
-
for (const [entryIdentity, entry] of this.#heldEntries) {
|
|
128
|
-
if (entry.key === key) this.#heldEntries.delete(entryIdentity)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// When a modifier key is released, clear any non-modifier keys still
|
|
133
|
-
// marked as held. On macOS, the OS intercepts modifier+key combos
|
|
134
|
-
// (e.g. Cmd+S) and swallows the keyup event for the non-modifier key,
|
|
135
|
-
// leaving it permanently stuck in the held set.
|
|
136
|
-
if (MODIFIER_KEYS.has(key)) {
|
|
137
|
-
for (const [entryIdentity, entry] of this.#heldEntries) {
|
|
138
|
-
if (!MODIFIER_KEYS.has(entry.key)) {
|
|
139
|
-
this.#heldEntries.delete(entryIdentity)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.#syncState()
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Clear all keys when window loses focus (keys might be released while not focused)
|
|
148
|
-
this.#blurListener = () => {
|
|
149
|
-
if (this.#heldEntries.size > 0) {
|
|
150
|
-
this.#heldEntries.clear()
|
|
151
|
-
this.#syncState()
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
document.addEventListener('keydown', this.#keydownListener, true)
|
|
156
|
-
document.addEventListener('keyup', this.#keyupListener, true)
|
|
157
|
-
window.addEventListener('blur', this.#blurListener)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Syncs the internal Set to the Store state.
|
|
162
|
-
*/
|
|
163
|
-
#syncState(): void {
|
|
164
|
-
const heldKeys = Array.from(
|
|
165
|
-
new Set(Array.from(this.#heldEntries.values(), (entry) => entry.key)),
|
|
166
|
-
)
|
|
167
|
-
const heldCodes = Object.fromEntries(
|
|
168
|
-
Array.from(this.#heldEntries.values(), (entry) => [
|
|
169
|
-
entry.key,
|
|
170
|
-
entry.code,
|
|
171
|
-
]),
|
|
172
|
-
)
|
|
173
|
-
this.store.setState(() => ({
|
|
174
|
-
heldKeys,
|
|
175
|
-
heldCodes,
|
|
176
|
-
}))
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Removes the keyboard event listeners.
|
|
181
|
-
*/
|
|
182
|
-
#removeListeners(): void {
|
|
183
|
-
if (typeof document === 'undefined') {
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this.#keydownListener) {
|
|
188
|
-
document.removeEventListener('keydown', this.#keydownListener, true)
|
|
189
|
-
this.#keydownListener = null
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.#keyupListener) {
|
|
193
|
-
document.removeEventListener('keyup', this.#keyupListener, true)
|
|
194
|
-
this.#keyupListener = null
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (this.#blurListener) {
|
|
198
|
-
window.removeEventListener('blur', this.#blurListener)
|
|
199
|
-
this.#blurListener = null
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Gets an array of currently held key names.
|
|
205
|
-
*
|
|
206
|
-
* @returns Array of key names currently being pressed
|
|
207
|
-
*/
|
|
208
|
-
getHeldKeys(): Array<string> {
|
|
209
|
-
return this.store.state.heldKeys
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Checks if a specific key is currently being held.
|
|
214
|
-
*
|
|
215
|
-
* @param key - The key name to check (case-insensitive)
|
|
216
|
-
* @returns True if the key is currently held
|
|
217
|
-
*/
|
|
218
|
-
isKeyHeld(key: string): boolean {
|
|
219
|
-
const normalizedKey = normalizeKeyName(key)
|
|
220
|
-
return Array.from(this.#heldEntries.values()).some(
|
|
221
|
-
(entry) => entry.key === normalizedKey,
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Checks if any of the given keys are currently held.
|
|
227
|
-
*
|
|
228
|
-
* @param keys - Array of key names to check
|
|
229
|
-
* @returns True if any of the keys are currently held
|
|
230
|
-
*/
|
|
231
|
-
isAnyKeyHeld(keys: Array<string>): boolean {
|
|
232
|
-
return keys.some((key) => this.isKeyHeld(key))
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Checks if all of the given keys are currently held.
|
|
237
|
-
*
|
|
238
|
-
* @param keys - Array of key names to check
|
|
239
|
-
* @returns True if all of the keys are currently held
|
|
240
|
-
*/
|
|
241
|
-
areAllKeysHeld(keys: Array<string>): boolean {
|
|
242
|
-
return keys.every((key) => this.isKeyHeld(key))
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Destroys the tracker and removes all listeners.
|
|
247
|
-
*/
|
|
248
|
-
destroy(): void {
|
|
249
|
-
this.#removeListeners()
|
|
250
|
-
this.#heldEntries.clear()
|
|
251
|
-
this.store.setState(() => getDefaultKeyStateTrackerState())
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Gets the singleton KeyStateTracker instance.
|
|
257
|
-
* Convenience function for accessing the tracker.
|
|
258
|
-
*/
|
|
259
|
-
export function getKeyStateTracker(): KeyStateTracker {
|
|
260
|
-
return KeyStateTracker.getInstance()
|
|
261
|
-
}
|
package/src/key.types.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import type { LOGICAL_ONLY_NAMED_KEYS, SHARED_NAMED_KEYS } from './_named-keys'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* All supported modifier key names, including aliases.
|
|
5
|
-
* - Control/Ctrl: The Control key
|
|
6
|
-
* - Shift: The Shift key
|
|
7
|
-
* - Alt/Option: The Alt key (Option on macOS)
|
|
8
|
-
* - Command/Cmd: The Command key (macOS only)
|
|
9
|
-
* - CommandOrControl/Mod: Command on macOS, Control on other platforms
|
|
10
|
-
*/
|
|
11
|
-
export type Modifier =
|
|
12
|
-
| 'Control'
|
|
13
|
-
| 'Ctrl'
|
|
14
|
-
| 'Shift'
|
|
15
|
-
| 'Alt'
|
|
16
|
-
| 'Option'
|
|
17
|
-
| 'Command'
|
|
18
|
-
| 'Cmd'
|
|
19
|
-
| 'CommandOrControl'
|
|
20
|
-
| 'Mod'
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Canonical modifier names that map to KeyboardEvent properties.
|
|
24
|
-
*/
|
|
25
|
-
export type CanonicalModifier = 'Control' | 'Shift' | 'Alt' | 'Meta'
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Letter keys A-Z (case-insensitive in matching).
|
|
29
|
-
*/
|
|
30
|
-
export type LetterKey =
|
|
31
|
-
| 'A'
|
|
32
|
-
| 'B'
|
|
33
|
-
| 'C'
|
|
34
|
-
| 'D'
|
|
35
|
-
| 'E'
|
|
36
|
-
| 'F'
|
|
37
|
-
| 'G'
|
|
38
|
-
| 'H'
|
|
39
|
-
| 'I'
|
|
40
|
-
| 'J'
|
|
41
|
-
| 'K'
|
|
42
|
-
| 'L'
|
|
43
|
-
| 'M'
|
|
44
|
-
| 'N'
|
|
45
|
-
| 'O'
|
|
46
|
-
| 'P'
|
|
47
|
-
| 'Q'
|
|
48
|
-
| 'R'
|
|
49
|
-
| 'S'
|
|
50
|
-
| 'T'
|
|
51
|
-
| 'U'
|
|
52
|
-
| 'V'
|
|
53
|
-
| 'W'
|
|
54
|
-
| 'X'
|
|
55
|
-
| 'Y'
|
|
56
|
-
| 'Z'
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Number keys 0-9.
|
|
60
|
-
*/
|
|
61
|
-
export type NumberKey =
|
|
62
|
-
| '0'
|
|
63
|
-
| '1'
|
|
64
|
-
| '2'
|
|
65
|
-
| '3'
|
|
66
|
-
| '4'
|
|
67
|
-
| '5'
|
|
68
|
-
| '6'
|
|
69
|
-
| '7'
|
|
70
|
-
| '8'
|
|
71
|
-
| '9'
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Function keys F1-F24, supported as both logical keys and physical codes.
|
|
75
|
-
*/
|
|
76
|
-
export type FunctionKey =
|
|
77
|
-
| 'F1'
|
|
78
|
-
| 'F2'
|
|
79
|
-
| 'F3'
|
|
80
|
-
| 'F4'
|
|
81
|
-
| 'F5'
|
|
82
|
-
| 'F6'
|
|
83
|
-
| 'F7'
|
|
84
|
-
| 'F8'
|
|
85
|
-
| 'F9'
|
|
86
|
-
| 'F10'
|
|
87
|
-
| 'F11'
|
|
88
|
-
| 'F12'
|
|
89
|
-
| 'F13'
|
|
90
|
-
| 'F14'
|
|
91
|
-
| 'F15'
|
|
92
|
-
| 'F16'
|
|
93
|
-
| 'F17'
|
|
94
|
-
| 'F18'
|
|
95
|
-
| 'F19'
|
|
96
|
-
| 'F20'
|
|
97
|
-
| 'F21'
|
|
98
|
-
| 'F22'
|
|
99
|
-
| 'F23'
|
|
100
|
-
| 'F24'
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Navigation keys for cursor movement.
|
|
104
|
-
*/
|
|
105
|
-
export type NavigationKey =
|
|
106
|
-
| 'ArrowUp'
|
|
107
|
-
| 'ArrowDown'
|
|
108
|
-
| 'ArrowLeft'
|
|
109
|
-
| 'ArrowRight'
|
|
110
|
-
| 'Home'
|
|
111
|
-
| 'End'
|
|
112
|
-
| 'PageUp'
|
|
113
|
-
| 'PageDown'
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Editing and special keys.
|
|
117
|
-
*/
|
|
118
|
-
export type EditingKey =
|
|
119
|
-
| 'Enter'
|
|
120
|
-
| 'Escape'
|
|
121
|
-
| 'Space'
|
|
122
|
-
| 'Tab'
|
|
123
|
-
| 'Backspace'
|
|
124
|
-
| 'Delete'
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Printable punctuation glyphs used in keyboard shortcuts. Matching uses the
|
|
128
|
-
* final KeyboardEvent.key glyph, independent of which layout produced it.
|
|
129
|
-
*/
|
|
130
|
-
export type PunctuationKey =
|
|
131
|
-
| '/'
|
|
132
|
-
| '['
|
|
133
|
-
| ']'
|
|
134
|
-
| '\\'
|
|
135
|
-
| '='
|
|
136
|
-
| '-'
|
|
137
|
-
| ','
|
|
138
|
-
| '.'
|
|
139
|
-
| ';'
|
|
140
|
-
| '`'
|
|
141
|
-
| "'"
|
|
142
|
-
| '+'
|
|
143
|
-
| '?'
|
|
144
|
-
| '!'
|
|
145
|
-
| '@'
|
|
146
|
-
| '#'
|
|
147
|
-
| '$'
|
|
148
|
-
| '%'
|
|
149
|
-
| '^'
|
|
150
|
-
| '&'
|
|
151
|
-
| '*'
|
|
152
|
-
| '('
|
|
153
|
-
| ')'
|
|
154
|
-
| '_'
|
|
155
|
-
| '{'
|
|
156
|
-
| '}'
|
|
157
|
-
| '|'
|
|
158
|
-
| ':'
|
|
159
|
-
| '"'
|
|
160
|
-
| '<'
|
|
161
|
-
| '>'
|
|
162
|
-
| '~'
|
|
163
|
-
|
|
164
|
-
/** Additional named logical keys, including media, browser, lock, and input-mode keys. */
|
|
165
|
-
export type NamedKey =
|
|
166
|
-
| (typeof SHARED_NAMED_KEYS)[number]
|
|
167
|
-
| (typeof LOGICAL_ONLY_NAMED_KEYS)[number]
|
|
168
|
-
|
|
169
|
-
/** Supported logical key names other than printable punctuation. */
|
|
170
|
-
export type NonPunctuationKey =
|
|
171
|
-
| LetterKey
|
|
172
|
-
| NumberKey
|
|
173
|
-
| EditingKey
|
|
174
|
-
| NavigationKey
|
|
175
|
-
| FunctionKey
|
|
176
|
-
| NamedKey
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Supported physical KeyboardEvent.code names, independent of keyboard layout.
|
|
180
|
-
* Letter, digit, numpad, and sided modifier names use finite template unions.
|
|
181
|
-
* `Unidentified` is excluded because it cannot identify a physical key.
|
|
182
|
-
*
|
|
183
|
-
* @see https://www.w3.org/TR/uievents-code/
|
|
184
|
-
*/
|
|
185
|
-
export type PhysicalKeyCode =
|
|
186
|
-
| `Key${LetterKey}`
|
|
187
|
-
| `Digit${NumberKey}`
|
|
188
|
-
| `Numpad${NumberKey}`
|
|
189
|
-
| `${'Alt' | 'Control' | 'Meta' | 'Shift'}${'Left' | 'Right'}`
|
|
190
|
-
| EditingKey
|
|
191
|
-
| NavigationKey
|
|
192
|
-
| FunctionKey
|
|
193
|
-
| (typeof SHARED_NAMED_KEYS)[number]
|
|
194
|
-
| 'Backquote'
|
|
195
|
-
| 'Backslash'
|
|
196
|
-
| 'BracketLeft'
|
|
197
|
-
| 'BracketRight'
|
|
198
|
-
| 'Comma'
|
|
199
|
-
| 'Equal'
|
|
200
|
-
| 'IntlBackslash'
|
|
201
|
-
| 'IntlRo'
|
|
202
|
-
| 'IntlYen'
|
|
203
|
-
| 'Minus'
|
|
204
|
-
| 'Period'
|
|
205
|
-
| 'Quote'
|
|
206
|
-
| 'Semicolon'
|
|
207
|
-
| 'Slash'
|
|
208
|
-
| `Lang${1 | 2 | 3 | 4 | 5}`
|
|
209
|
-
| `Numpad${
|
|
210
|
-
| 'Add'
|
|
211
|
-
| 'Backspace'
|
|
212
|
-
| 'Clear'
|
|
213
|
-
| 'ClearEntry'
|
|
214
|
-
| 'Comma'
|
|
215
|
-
| 'Decimal'
|
|
216
|
-
| 'Divide'
|
|
217
|
-
| 'Enter'
|
|
218
|
-
| 'Equal'
|
|
219
|
-
| 'Hash'
|
|
220
|
-
| 'MemoryAdd'
|
|
221
|
-
| 'MemoryClear'
|
|
222
|
-
| 'MemoryRecall'
|
|
223
|
-
| 'MemoryStore'
|
|
224
|
-
| 'MemorySubtract'
|
|
225
|
-
| 'Multiply'
|
|
226
|
-
| 'ParenLeft'
|
|
227
|
-
| 'ParenRight'
|
|
228
|
-
| 'Star'
|
|
229
|
-
| 'Subtract'}`
|
|
230
|
-
| 'LaunchApp1'
|
|
231
|
-
| 'LaunchApp2'
|
|
232
|
-
| 'MediaSelect'
|
|
233
|
-
| 'Sleep'
|
|
234
|
-
| 'Turbo'
|
|
235
|
-
| 'Abort'
|
|
236
|
-
| 'Resume'
|
|
237
|
-
| 'Suspend'
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* An explicit physical key token. All codes use brackets, including names such
|
|
241
|
-
* as `[Enter]` that also exist as logical keys. Invalid code names are rejected
|
|
242
|
-
* by TypeScript, and supported names are available in autocomplete.
|
|
243
|
-
*/
|
|
244
|
-
export type PhysicalKey = `[${PhysicalKeyCode}]`
|
|
245
|
-
|
|
246
|
-
/** Supported logical key names, excluding bracketed physical-code syntax. */
|
|
247
|
-
export type LogicalKey = NonPunctuationKey | PunctuationKey
|
|
248
|
-
|
|
249
|
-
/** All supported logical keys and bracketed physical key tokens. */
|
|
250
|
-
export type Key = LogicalKey | PhysicalKey
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Includes both modifier keys and regular keys.
|
|
254
|
-
*/
|
|
255
|
-
export type IndividualKey = CanonicalModifier | Key
|
|
256
|
-
|
|
257
|
-
/** Keyboard event properties normalized for internal matching and recording. */
|
|
258
|
-
export interface NormalizedKeyboardEvent {
|
|
259
|
-
key: string
|
|
260
|
-
code: string
|
|
261
|
-
ctrl: boolean
|
|
262
|
-
shift: boolean
|
|
263
|
-
alt: boolean
|
|
264
|
-
meta: boolean
|
|
265
|
-
altGraph: boolean
|
|
266
|
-
location: number
|
|
267
|
-
isComposing: boolean
|
|
268
|
-
}
|