From 174f525145e5e601faaa171fc027d530f90a6bc4 Mon Sep 17 00:00:00 2001 From: Andre <200930841+Andre-Bzk@users.noreply.github.com> Date: Sun, 12 Apr 2026 15:43:29 +0200 Subject: [PATCH] Fix: Entdoppelte Gamepad-Eingaben bei externen Controllern - Browser-Gamepad-Pfad unter Linux deaktiviert - nahezu zeitgleiche identische Eingaben aus mehreren /dev/input/js*-Devices entdoppelt - doppelte D-Pad-Bewegungen bei Bluetooth-/USB-Controllern verhindert --- src/main/input/gamepadReader.ts | 9 +++++++++ src/renderer/src/App.tsx | 1 + 2 files changed, 10 insertions(+) diff --git a/src/main/input/gamepadReader.ts b/src/main/input/gamepadReader.ts index f992687..80dd795 100644 --- a/src/main/input/gamepadReader.ts +++ b/src/main/input/gamepadReader.ts @@ -36,6 +36,9 @@ const REPEAT_INTERVAL_MS = 150 // L2/R2 Trigger: kein Auto-Repeat, da 300s-Spruenge nicht wiederholt werden sollen. const NO_REPEAT_AXES = new Set([2, 5]) const SCAN_INTERVAL_MS = 3000 +// Bluetooth-/Steam-Setups liefern dieselbe Eingabe teils über mehrere js*-Devices. +// Nahezu zeitgleiche identische Events werden deshalb global entdoppelt. +const DUPLICATE_EVENT_WINDOW_MS = 40 interface AxisState { key: string | null @@ -177,8 +180,14 @@ export function startGamepadReader(getWindow: () => BrowserWindow | null): () => if (process.platform !== 'linux') return () => {} const readers = new Map() + const lastKeyAt = new Map() const onKey = (key: string): void => { + const now = Date.now() + const lastAt = lastKeyAt.get(key) ?? 0 + if (now - lastAt < DUPLICATE_EVENT_WINDOW_MS) return + lastKeyAt.set(key, now) + const win = getWindow() if (!win || win.isDestroyed()) return win.webContents.send('gamepad-input', key) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 3b3ce2f..1acf4d9 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -22,6 +22,7 @@ export default function App(): JSX.Element { // Browser Gamepad API (funktioniert im Desktop-Modus / Windows) useEffect(() => { + if (navigator.userAgent.toLowerCase().includes('linux')) return gamepadService.start() return () => gamepadService.stop() }, [])