diondiondion 149b5b7989 [Glitch] Change Page Up/Page Down hotkeys to require Alt modifier key
Port 083b325a9a89b2eb73e490595e987440cd544093 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-06-16 21:52:32 +02:00

46 lines
1015 B
TypeScript

export function isKeyboardEvent(event: Event): event is KeyboardEvent {
return 'key' in event;
}
/**
* Normalises key values to consistent lowercase strings
*/
export function normalizeKey(key: string): string {
const lowerKey = key.toLowerCase();
switch (lowerKey) {
case ' ':
case 'spacebar': // for older browsers
return 'space';
case 'arrowup':
return 'up';
case 'arrowdown':
return 'down';
case 'arrowleft':
return 'left';
case 'arrowright':
return 'right';
case 'esc':
case 'escape':
return 'escape';
default:
return lowerKey;
}
}
/**
* Compare whether a key matches an `event.code` value,
* with support for single-letter keys (which are otherwise
* represented with a `Key` prefix, e.g. `m` is `KeyM`).
*/
export function matchesKeyCode(key: string, code: string) {
if (key.length === 1) {
return code === `Key${key.toUpperCase()}`;
} else {
return code.toLowerCase() === key.toLowerCase();
}
}