stable-diffusion-webui/javascript/imageviewerGamepad.js

34 lines
893 B
JavaScript
Raw Normal View History

2023-05-06 04:48:27 +00:00
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) {
2023-03-13 08:39:02 +00:00
modalPrevImage(e);
2023-05-06 04:48:27 +00:00
} else if (xValue > 0.3) {
2023-03-13 08:39:02 +00:00
modalNextImage(e);
}
2023-05-06 04:48:27 +00:00
}, 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);
}
2023-03-13 08:39:02 +00:00
2023-05-06 04:48:27 +00:00
setTimeout(() => {
isScrolling = false;
}, delay);
});