From b4f050f1aae07da041b4d4afef636257f9b9d832 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 15 Jun 2024 23:52:46 +0200 Subject: prevent gamepad buttons from repeating actions It now waits until the button has been released before that button can again do its action. --- src/app/js/gamepad.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/app') diff --git a/src/app/js/gamepad.js b/src/app/js/gamepad.js index fea2ee2..aa9e089 100644 --- a/src/app/js/gamepad.js +++ b/src/app/js/gamepad.js @@ -20,6 +20,8 @@ window.addEventListener("gamepaddisconnected", (e) => { // be pressed again let delay_press = {}; +let held_buttons = {}; + setInterval(() => { let gamepads = navigator.getGamepads(); @@ -87,6 +89,7 @@ setInterval(() => { for (let ii = 0; ii < gamepads[i].buttons.length; ii++) { if (! gamepads[i].buttons[ii].pressed) { + held_buttons[ii] = false; continue; } @@ -149,6 +152,12 @@ setInterval(() => { // immediately again after this delay_press[ii] = 3; + if (held_buttons[ii]) { + continue; + } + + held_buttons[ii] = true; + // interpret `ii` as a specific button/action, using the // standard IDs: https://w3c.github.io/gamepad/#remapping switch(ii) { -- cgit v1.2.3