Files
pihkaal-me/app/composables/useKeyDown.ts
Pihkaal f4ebe93135
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m31s
feat(nds): use key codes instead of keys to handle multiple layouts
2026-02-16 13:57:26 +01:00

27 lines
626 B
TypeScript

import { mapCodeToNDS } from "~/utils/input";
export type KeyDownCallback = (params: {
key: string;
ndsButton: string | null;
repeated: boolean;
}) => void;
export const useKeyDown = (callback: KeyDownCallback) => {
const handleKeyDown = (event: KeyboardEvent) => {
const ndsButton = mapCodeToNDS(event.code);
callback({
key: ndsButton ? `NDS_${ndsButton}` : event.key,
ndsButton,
repeated: event.repeat,
});
};
onMounted(() => {
window.addEventListener("keydown", handleKeyDown);
});
onUnmounted(() => {
window.removeEventListener("keydown", handleKeyDown);
});
};