feat(nds): use custom NDS_ keys in events

This commit is contained in:
2025-12-15 11:53:20 +01:00
parent 1bd1b70313
commit 258bcd0f16
3 changed files with 40 additions and 52 deletions

View File

@@ -51,14 +51,14 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
}
});
const handleKeyPress = (event: KeyboardEvent) => {
useKeyDown((key) => {
const currentButton = selectedButton.value as keyof T;
const currentNav = navigation[currentButton];
if (!currentNav) return;
switch (event.key) {
case "ArrowUp":
switch (key) {
case "NDS_UP":
if (!currentNav.up) return;
if (currentNav.up === "last") {
@@ -76,7 +76,7 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
break;
case "ArrowDown":
case "NDS_DOWN":
if (!currentNav.down) return;
if (currentNav.down === "last") {
@@ -93,7 +93,7 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
}
break;
case "ArrowLeft":
case "NDS_LEFT":
if (!currentNav.left) return;
if (currentNav.horizontalMode === "preview") {
@@ -103,7 +103,7 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
}
break;
case "ArrowRight":
case "NDS_RIGHT":
if (!currentNav.right) return;
if (currentNav.horizontalMode === "preview") {
@@ -113,24 +113,13 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
}
break;
case "Enter":
case " ":
case "NDS_A":
onButtonClick?.(selectedButton.value);
break;
default:
return;
}
event.preventDefault();
};
onMounted(() => {
window.addEventListener("keydown", handleKeyPress);
});
onUnmounted(() => {
window.removeEventListener("keydown", handleKeyPress);
});
return {