From b8d793daf909cf1eda62fe33a33920ac4e9b4293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 13 Mar 2026 16:31:02 +0100 Subject: [PATCH] Repeat key handling: Clear held keys when turning off focus movement --- Common/UI/Root.cpp | 57 ++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index e2d4e9016b..12c81db67c 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -19,6 +19,34 @@ bool focusForced; static std::function soundCallback; +// Repeat key handling below. +// TODO: Figure out where this should really live. +// Simple simulation of key repeat on platforms and for gamepads where we don't +// automatically get it. + +static int frameCount; + +// Ignore deviceId when checking for matches. Turns out that Ouya for example sends +// completely broken input where the original keypresses have deviceId = 10 and the repeats +// have deviceId = 0. +struct HeldKey { + InputKeyCode key; + InputDeviceID deviceId; + double triggerTime; + + // Ignores startTime + bool operator <(const HeldKey &other) const { + if (key < other.key) return true; + return false; + } + bool operator ==(const HeldKey &other) const { return key == other.key; } +}; + +static std::set heldKeys; + +const double repeatDelay = 15 * (1.0 / 60.0f); // 15 frames like before. +const double repeatInterval = 5 * (1.0 / 60.0f); // 5 frames like before. + struct DispatchQueueItem { Event *e; EventParams params; @@ -93,6 +121,8 @@ void EnableFocusMovement(bool enable) { if (focusedView) { focusedView->FocusChanged(FF_LOSTFOCUS); } + focusMoves.clear(); + heldKeys.clear(); focusedView = nullptr; } } @@ -145,33 +175,6 @@ void PlayUISound(UISound sound) { } } -// TODO: Figure out where this should really live. -// Simple simulation of key repeat on platforms and for gamepads where we don't -// automatically get it. - -static int frameCount; - -// Ignore deviceId when checking for matches. Turns out that Ouya for example sends -// completely broken input where the original keypresses have deviceId = 10 and the repeats -// have deviceId = 0. -struct HeldKey { - InputKeyCode key; - InputDeviceID deviceId; - double triggerTime; - - // Ignores startTime - bool operator <(const HeldKey &other) const { - if (key < other.key) return true; - return false; - } - bool operator ==(const HeldKey &other) const { return key == other.key; } -}; - -static std::set heldKeys; - -const double repeatDelay = 15 * (1.0 / 60.0f); // 15 frames like before. -const double repeatInterval = 5 * (1.0 / 60.0f); // 5 frames like before. - bool IsScrollKey(const KeyInput &input) { switch (input.keyCode) { case NKCODE_PAGE_UP: