aboutsummaryrefslogtreecommitdiff
path: root/javascript/imageviewerGamepad.js
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-05-31 19:31:19 +0300
committerGitHub <noreply@github.com>2023-05-31 19:31:19 +0300
commit177d4b6828eee6a9aa1e9f2cf4877ad9ae8fcae4 (patch)
tree466c92812f7b978cf3a535187c18be78c4e26d37 /javascript/imageviewerGamepad.js
parentc1a5068ebea127412dfaaa6598795196a64200f1 (diff)
parent881de0df38c1fa6d0d61f7bc6fc93c100a9f35d0 (diff)
Merge branch 'dev' into sync-req
Diffstat (limited to 'javascript/imageviewerGamepad.js')
-rw-r--r--javascript/imageviewerGamepad.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js
index 31d226de..a22c7e6e 100644
--- a/javascript/imageviewerGamepad.js
+++ b/javascript/imageviewerGamepad.js
@@ -1,7 +1,9 @@
+let gamepads = [];
+
window.addEventListener('gamepadconnected', (e) => {
const index = e.gamepad.index;
let isWaiting = false;
- setInterval(async() => {
+ gamepads[index] = setInterval(async() => {
if (!opts.js_modal_lightbox_gamepad || isWaiting) return;
const gamepad = navigator.getGamepads()[index];
const xValue = gamepad.axes[0];
@@ -24,6 +26,10 @@ window.addEventListener('gamepadconnected', (e) => {
}, 10);
});
+window.addEventListener('gamepaddisconnected', (e) => {
+ clearInterval(gamepads[e.gamepad.index]);
+});
+
/*
Primarily for vr controller type pointer devices.
I use the wheel event because there's currently no way to do it properly with web xr.