(char: string)
| 123 | * @returns Key code, or null if not a valid single-char key |
| 124 | */ |
| 125 | export function charToKeyCode(char: string): number | null { |
| 126 | if (char.length !== 1) return null; |
| 127 | |
| 128 | const code = char.charCodeAt(0); |
| 129 | |
| 130 | // Lowercase letters -> uppercase |
| 131 | if (code >= 97 && code <= 122) { |
| 132 | return code - 32; // 'a' (97) -> 'A' (65) |
| 133 | } |
| 134 | |
| 135 | // Uppercase letters |
| 136 | if (code >= 65 && code <= 90) { |
| 137 | return code; |
| 138 | } |
| 139 | |
| 140 | // Digits |
| 141 | if (code >= 48 && code <= 57) { |
| 142 | return code; |
| 143 | } |
| 144 | |
| 145 | // Common punctuation/symbols (use ASCII directly) |
| 146 | // This includes: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ |
| 147 | if (code >= 32 && code <= 126) { |
| 148 | return code; |
| 149 | } |
| 150 | |
| 151 | return null; |
| 152 | } |
| 153 | |
| 154 | /** Empty modifiers object (all false). */ |
| 155 | const MODS_BY_MASK: readonly Modifiers[] = (() => { |
no outgoing calls