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
This commit is contained in:
Andre
2026-04-12 15:43:29 +02:00
parent 028e56e2cb
commit 174f525145
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -36,6 +36,9 @@ const REPEAT_INTERVAL_MS = 150
// L2/R2 Trigger: kein Auto-Repeat, da 300s-Spruenge nicht wiederholt werden sollen. // L2/R2 Trigger: kein Auto-Repeat, da 300s-Spruenge nicht wiederholt werden sollen.
const NO_REPEAT_AXES = new Set([2, 5]) const NO_REPEAT_AXES = new Set([2, 5])
const SCAN_INTERVAL_MS = 3000 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 { interface AxisState {
key: string | null key: string | null
@@ -177,8 +180,14 @@ export function startGamepadReader(getWindow: () => BrowserWindow | null): () =>
if (process.platform !== 'linux') return () => {} if (process.platform !== 'linux') return () => {}
const readers = new Map<string, JoystickReader>() const readers = new Map<string, JoystickReader>()
const lastKeyAt = new Map<string, number>()
const onKey = (key: string): void => { 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() const win = getWindow()
if (!win || win.isDestroyed()) return if (!win || win.isDestroyed()) return
win.webContents.send('gamepad-input', key) win.webContents.send('gamepad-input', key)
+1
View File
@@ -22,6 +22,7 @@ export default function App(): JSX.Element {
// Browser Gamepad API (funktioniert im Desktop-Modus / Windows) // Browser Gamepad API (funktioniert im Desktop-Modus / Windows)
useEffect(() => { useEffect(() => {
if (navigator.userAgent.toLowerCase().includes('linux')) return
gamepadService.start() gamepadService.start()
return () => gamepadService.stop() return () => gamepadService.stop()
}, []) }, [])