diff options
author | 0neGal <mail@0negal.com> | 2024-06-15 23:52:46 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-06-15 23:52:46 +0200 |
commit | b4f050f1aae07da041b4d4afef636257f9b9d832 (patch) | |
tree | 81396d799d0cb55e0eecf214756352e68dcf43a2 /src/app/js | |
parent | 0da4d19ec0d0bc0d63bb615bc1e642bb6aeecd31 (diff) | |
download | Viper-b4f050f1aae07da041b4d4afef636257f9b9d832.tar.gz Viper-b4f050f1aae07da041b4d4afef636257f9b9d832.zip |
prevent gamepad buttons from repeating actions
It now waits until the button has been released before that button can
again do its action.
Diffstat (limited to 'src/app/js')
-rw-r--r-- | src/app/js/gamepad.js | 9 |
1 files changed, 9 insertions, 0 deletions
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) { |