diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-04-29 16:43:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-29 16:43:34 +0000 |
commit | 45371704f6eea2d9c52bab1bd658f1ba2ba2620c (patch) | |
tree | d471fced38c56a7f5af5f249ca97fedb22133b6b /javascript/imageviewerGamepad.js | |
parent | e40b2d947d874ed5504701bfd8e32243e0c456eb (diff) | |
parent | 54291f9d63f0c7dc445b90f3afb37fc330739557 (diff) | |
download | stable-diffusion-webui-gfx803-45371704f6eea2d9c52bab1bd658f1ba2ba2620c.tar.gz stable-diffusion-webui-gfx803-45371704f6eea2d9c52bab1bd658f1ba2ba2620c.tar.bz2 stable-diffusion-webui-gfx803-45371704f6eea2d9c52bab1bd658f1ba2ba2620c.zip |
Merge pull request #7632 from papuSpartan/gamepad
Image viewer scrolling via analog stick
Diffstat (limited to 'javascript/imageviewerGamepad.js')
-rw-r--r-- | javascript/imageviewerGamepad.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js new file mode 100644 index 00000000..29bd7140 --- /dev/null +++ b/javascript/imageviewerGamepad.js @@ -0,0 +1,36 @@ + let delay = 350//ms + window.addEventListener('gamepadconnected', (e) => { + console.log("Gamepad connected!") + const gamepad = e.gamepad; + setInterval(() => { + const xValue = gamepad.axes[0].toFixed(2); + if (xValue < -0.3) { + modalPrevImage(e); + } else if (xValue > 0.3) { + modalNextImage(e); + } + + }, delay); + }); + + + /* + 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. + */ + + let isScrolling = false; + window.addEventListener('wheel', (e) => { + if (isScrolling) return; + isScrolling = true; + + if (e.deltaX <= -0.6) { + modalPrevImage(e); + } else if (e.deltaX >= 0.6) { + modalNextImage(e); + } + + setTimeout(() => { + isScrolling = false; + }, delay); + });
\ No newline at end of file |