feat(nds): improve key input system

This commit is contained in:
2026-02-10 16:28:54 +01:00
parent 38b36d0e1c
commit a95feb223e
16 changed files with 59 additions and 102 deletions

View File

@@ -221,7 +221,7 @@ export const useButtonNavigation = <T extends Record<string, Rect>>({
}
});
useKeyDown((key) => {
useKeyDown(({ key }) => {
if (blockInteractions.value) return;
const currentButton = selectedButton.value as Entry;

View File

@@ -1,8 +1,19 @@
export type KeyDownCallback = (key: string) => void;
import { mapKeyToNDS } from "~/utils/input";
export type KeyDownCallback = (params: {
key: string;
ndsButton: string | null;
repeated: boolean;
}) => void;
export const useKeyDown = (callback: KeyDownCallback) => {
const handleKeyDown = (event: KeyboardEvent) => {
callback(event.key);
const ndsButton = mapKeyToNDS(event.key);
callback({
key: ndsButton ? `NDS_${ndsButton}` : event.key,
ndsButton,
repeated: event.repeat,
});
};
onMounted(() => {

View File

@@ -1,8 +1,17 @@
export type KeyUpCallback = (key: string) => void;
import { mapKeyToNDS } from "~/utils/input";
export type KeyUpCallback = (params: {
key: string;
ndsButton: string | null;
}) => void;
export const useKeyUp = (callback: KeyUpCallback) => {
const handleKeyUp = (event: KeyboardEvent) => {
callback(event.key);
const ndsButton = mapKeyToNDS(event.key);
callback({
key: ndsButton ? `NDS_${ndsButton}` : event.key,
ndsButton,
});
};
onMounted(() => {