Files
pihkaal-me/app/composables/useKeyUp.ts

25 lines
556 B
TypeScript

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