Files
pihkaal-me/app/composables/useKeyUp.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

25 lines
559 B
TypeScript

import { mapCodeToNDS } from "~/utils/input";
export type KeyUpCallback = (params: {
key: string;
ndsButton: string | null;
}) => void;
export const useKeyUp = (callback: KeyUpCallback) => {
const handleKeyUp = (event: KeyboardEvent) => {
const ndsButton = mapCodeToNDS(event.code);
callback({
key: ndsButton ? `NDS_${ndsButton}` : event.key,
ndsButton,
});
};
onMounted(() => {
window.addEventListener("keyup", handleKeyUp);
});
onUnmounted(() => {
window.removeEventListener("keyup", handleKeyUp);
});
};