diff --git a/app/composables/useKeyDown.ts b/app/composables/useKeyDown.ts index 8fb22e5..5761611 100644 --- a/app/composables/useKeyDown.ts +++ b/app/composables/useKeyDown.ts @@ -1,4 +1,4 @@ -import { mapKeyToNDS } from "~/utils/input"; +import { mapCodeToNDS } from "~/utils/input"; export type KeyDownCallback = (params: { key: string; @@ -8,7 +8,7 @@ export type KeyDownCallback = (params: { export const useKeyDown = (callback: KeyDownCallback) => { const handleKeyDown = (event: KeyboardEvent) => { - const ndsButton = mapKeyToNDS(event.key); + const ndsButton = mapCodeToNDS(event.code); callback({ key: ndsButton ? `NDS_${ndsButton}` : event.key, ndsButton, diff --git a/app/composables/useKeyUp.ts b/app/composables/useKeyUp.ts index 4c916ad..603309a 100644 --- a/app/composables/useKeyUp.ts +++ b/app/composables/useKeyUp.ts @@ -1,4 +1,4 @@ -import { mapKeyToNDS } from "~/utils/input"; +import { mapCodeToNDS } from "~/utils/input"; export type KeyUpCallback = (params: { key: string; @@ -7,7 +7,7 @@ export type KeyUpCallback = (params: { export const useKeyUp = (callback: KeyUpCallback) => { const handleKeyUp = (event: KeyboardEvent) => { - const ndsButton = mapKeyToNDS(event.key); + const ndsButton = mapCodeToNDS(event.code); callback({ key: ndsButton ? `NDS_${ndsButton}` : event.key, ndsButton, diff --git a/app/utils/input.ts b/app/utils/input.ts index 4940eb1..65e96bd 100644 --- a/app/utils/input.ts +++ b/app/utils/input.ts @@ -1,19 +1,18 @@ -const KEY_TO_NDS_BUTTON: Record = { +const CODE_TO_NDS_BUTTON: Record = { ArrowUp: "UP", ArrowDown: "DOWN", ArrowLeft: "LEFT", ArrowRight: "RIGHT", - D: "A", - S: "B", - Z: "X", - Q: "Y", - " ": "SELECT", + KeyD: "A", + KeyS: "B", + KeyW: "X", + KeyA: "Y", + Space: "SELECT", Enter: "START", }; -export const mapKeyToNDS = (key: string): string | null => { - key = key.length === 1 ? key.toUpperCase() : key; - return KEY_TO_NDS_BUTTON[key] ?? null; +export const mapCodeToNDS = (code: string): string | null => { + return CODE_TO_NDS_BUTTON[code] ?? null; }; export const useMouseUp = (callback: () => void) => {