mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-12-06 10:31:17 -08:00
Make gamepad navigation optional
This commit is contained in:
parent
5ab7f213be
commit
a46c23b10f
2 changed files with 30 additions and 32 deletions
|
|
@ -1,36 +1,33 @@
|
|||
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) {
|
||||
const delay = 250//ms
|
||||
window.addEventListener('gamepadconnected', (e) => {
|
||||
setInterval(() => {
|
||||
if (!opts.js_modal_lightbox_gamepad) return;
|
||||
const gamepad = navigator.getGamepads()[0];
|
||||
const xValue = gamepad.axes[0];
|
||||
if (xValue < -0.3) {
|
||||
modalPrevImage(e);
|
||||
} else if (e.deltaX >= 0.6) {
|
||||
} else if (xValue > 0.3) {
|
||||
modalNextImage(e);
|
||||
}
|
||||
}, delay);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
isScrolling = false;
|
||||
}, 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 (!opts.js_modal_lightbox_gamepad || isScrolling) return;
|
||||
isScrolling = true;
|
||||
|
||||
if (e.deltaX <= -0.6) {
|
||||
modalPrevImage(e);
|
||||
} else if (e.deltaX >= 0.6) {
|
||||
modalNextImage(e);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
isScrolling = false;
|
||||
}, delay);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue