All checks were successful
Build and Push Docker Image / build (push) Successful in 2m31s
25 lines
559 B
TypeScript
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);
|
|
});
|
|
};
|