From 7920d3a44b4d77a0ffb2d95e0d32fe5d36d3c57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 29 Jan 2024 18:41:43 +0100 Subject: [PATCH] Release all keys on pause. Fixes #18767 Not sure about merging for the 1.17 series though, maybe someone really likes to bring up the pause menu briefly while holding a direction.. we could actually handle that with some extra logic. --- Core/ControlMapper.cpp | 36 ++++++++++++++++++++++++++++++++++++ Core/ControlMapper.h | 3 +++ UI/EmuScreen.cpp | 1 + 3 files changed, 40 insertions(+) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index 17c8e9ff9e..33a9395fc1 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -231,6 +231,42 @@ void ControlMapper::ForceReleaseVKey(int vkey) { KeyMap::UnlockMappings(); } +void ControlMapper::ReleaseAll() { + std::vector axes; + std::vector keys; + + { + std::lock_guard guard(mutex_); + + for (const auto &input : curInput_) { + if (input.first.IsAxis()) { + if (input.second.value != 0.0f) { + AxisInput axis; + axis.deviceId = input.first.deviceId; + int dir; + axis.axisId = (InputAxis)input.first.Axis(&dir); + axis.value = 0.0; + axes.push_back(axis); + } + } else { + if (input.second.value != 0.0) { + KeyInput key; + key.deviceId = input.first.deviceId; + key.flags = KEY_UP; + key.keyCode = (InputKeyCode)input.first.keyCode; + keys.push_back(key); + } + } + } + } + + Axis(axes.data(), axes.size());; + for (const auto &key : keys) { + Key(key, nullptr); + } +} + + static int RotatePSPKeyCode(int x) { switch (x) { case CTRL_UP: return CTRL_RIGHT; diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index d7f2414e42..313453bac0 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -40,6 +40,9 @@ public: // Might replace this later by allowing through "key-up" and similar events to lower screens. void ForceReleaseVKey(int vkey); + // Call when the emu screen gets pushed behind some other screen, like the pause screen, to release all "down" inputs. + void ReleaseAll(); + void GetDebugString(char *buffer, size_t bufSize) const; struct InputSample { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 11bc8b26eb..2075fb3338 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -496,6 +496,7 @@ void EmuScreen::focusChanged(ScreenFocusChange focusChange) { switch (focusChange) { case ScreenFocusChange::FOCUS_LOST_TOP: g_Config.TimeTracker().Stop(gameID); + controlMapper_.ReleaseAll(); break; case ScreenFocusChange::FOCUS_BECAME_TOP: g_Config.TimeTracker().Start(gameID);