feat: dispatch key up event when in 2d mode

This commit is contained in:
2025-12-22 17:14:24 +01:00
parent 4745a49a63
commit fcd51ff91f

View File

@@ -17,13 +17,7 @@ const bottomScreen = useTemplateRef<ScreenInstance>("bottomScreen");
const topScreenCanvas = computed(() => topScreen.value?.canvas ?? null);
const bottomScreenCanvas = computed(() => bottomScreen.value?.canvas ?? null);
useKeyDown((key) => {
// events are dispatched from NDS.vue in 3d mode
// events are dispatched from here in 2d mode
// that's a bit dirty but who cares, there is a lot of dirty things going on here
// like who choose Nuxt to build such an app
if (ENABLE_3D) return;
const keyToButton: Record<string, string> = {
const keyToButton: Record<string, string> = {
ArrowUp: "UP",
ArrowDown: "DOWN",
ArrowLeft: "LEFT",
@@ -34,7 +28,14 @@ useKeyDown((key) => {
a: "Y",
" ": "SELECT",
Enter: "START",
};
};
// events are dispatched from NDS.vue in 3d mode
// events are dispatched from here in 2d mode
// that's a bit dirty but who cares, there is a lot of dirty things going on here
// like who choose Nuxt to build such an app
useKeyDown((key) => {
if (ENABLE_3D) return;
const button = keyToButton[key];
if (button) {
window.dispatchEvent(
@@ -42,6 +43,14 @@ useKeyDown((key) => {
);
}
});
useKeyUp((key) => {
if (ENABLE_3D) return;
const button = keyToButton[key];
if (button) {
window.dispatchEvent(new KeyboardEvent("keyup", { key: `NDS_${button}` }));
}
});
</script>
<template>