@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 14 lines 698 Bytes
Raw
1 type SurfaceKeyEvent = Pick<KeyboardEvent, "key"> &
2 Partial<Pick<KeyboardEvent, "code" | "getModifierState">>;
3
4 export function surfaceShortcutKey(event: SurfaceKeyEvent): string | null {
5 // AltGr text must stay text even when the browser omits Ctrl and Alt.
6 if (event.getModifierState?.("AltGraph") && !/^[a-z0-9]$/i.test(event.key)) return null;
7 const typed = event.key.toLowerCase();
8 // Preserve Latin layouts, punctuation and dead keys; non-Latin letters/marks use the physical key.
9 const physical =
10 /^[\p{L}\p{M}]+$/u.test(typed) && !/\p{Script=Latin}/u.test(typed)
11 ? event.code?.match(/^Key([A-Z])$/)?.[1]?.toLowerCase()
12 : undefined;
13 return physical ?? typed;
14 }