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

@@ -203,38 +203,15 @@ const { onRender } = useLoop();
const physicalButtonsDown = new Set<string>();
let mousePressedButton: string | null = null;
const keyToButton: Record<string, string> = {
ArrowUp: "UP",
ArrowDown: "DOWN",
ArrowLeft: "LEFT",
ArrowRight: "RIGHT",
d: "A",
s: "B",
w: "X",
a: "Y",
D: "A",
S: "B",
W: "X",
A: "Y",
" ": "SELECT",
Enter: "START",
};
useKeyDown((key) => {
const button = keyToButton[key];
if (button) {
physicalButtonsDown.add(button);
window.dispatchEvent(
new KeyboardEvent("keydown", { key: `NDS_${button}` }),
);
useKeyDown(({ ndsButton }) => {
if (ndsButton) {
physicalButtonsDown.add(ndsButton);
}
});
useKeyUp((key) => {
const button = keyToButton[key];
if (button) {
physicalButtonsDown.delete(button);
window.dispatchEvent(new KeyboardEvent("keyup", { key: `NDS_${button}` }));
useKeyUp(({ ndsButton }) => {
if (ndsButton) {
physicalButtonsDown.delete(ndsButton);
}
});