* Resolve the binding key from a KeyboardEvent. * * Layout-aware: when `event.key` is a single printable ASCII char it * reflects what the active keyboard layout *typed* (Colemak/Dvorak * users want `Cmd+P` to fire on whichever physical key produces `p`, * not on the QWERTY-P position). Letters
(event: KeyboardEvent)
| 1170 | * `normalizeKeyName(event.key)`. |
| 1171 | */ |
| 1172 | function resolveKeyFromEvent(event: KeyboardEvent): string | null { |
| 1173 | if (isModifierKey(event.key)) return null; |
| 1174 | const k = event.key; |
| 1175 | // Skip the typed-char fast path for '+': it is the binding-string |
| 1176 | // separator, so emitting it would produce unparsable strings like |
| 1177 | // "Mod+Shift++". Fall through to physicalKeyFromCode (event.code |
| 1178 | // = "Equal" -> "=" for Shift+Cmd+=). |
| 1179 | if (k.length === 1 && k !== "+") { |
| 1180 | const cp = k.charCodeAt(0); |
| 1181 | if (cp > 0x20 && cp < 0x7f) { |
| 1182 | return k.toUpperCase(); |
| 1183 | } |
| 1184 | } |
| 1185 | return physicalKeyFromCode(event.code); |
| 1186 | } |
| 1187 | |
| 1188 | function normalizeKeyName(key: string): string | null { |
| 1189 | if (!key) return null; |
no test coverage detected