From b921a52071cf2a5e551c31a6073af6eaebbf7847 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 28 Jan 2023 03:19:10 -0600 Subject: [PATCH] basic image next and prev control with joystick --- javascript/imageviewer.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/javascript/imageviewer.js b/javascript/imageviewer.js index 67916536e..0488bfb43 100644 --- a/javascript/imageviewer.js +++ b/javascript/imageviewer.js @@ -210,6 +210,19 @@ document.addEventListener("DOMContentLoaded", function() { modal.id = "lightboxModal"; modal.tabIndex = 0 modal.addEventListener('keydown', modalKeyHandler, true) + 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(); + } else if (xValue > 0.3) { + modalNextImage(); + } + + }, 350); + }); const modalControls = document.createElement('div') modalControls.className = 'modalControls gradio-container';