diff --git a/rpcs3/Emu/Io/KeyboardHandler.cpp b/rpcs3/Emu/Io/KeyboardHandler.cpp index edcea3e903..add28a1911 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.cpp +++ b/rpcs3/Emu/Io/KeyboardHandler.cpp @@ -186,3 +186,14 @@ void KeyboardHandlerBase::SetIntercepted(bool intercepted) } } } + +void KeyboardHandlerBase::ReleaseAllKeys() +{ + for (const Keyboard& keyboard : m_keyboards) + { + for (const KbButton& button : keyboard.m_buttons) + { + Key(button.m_keyCode, false); + } + } +} diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 630dd147e8..8538be319b 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -86,10 +86,6 @@ struct Keyboard class KeyboardHandlerBase { -protected: - KbInfo m_info; - std::vector m_keyboards; - public: std::mutex m_mutex; @@ -109,4 +105,10 @@ public: KbConfig& GetConfig(const u32 keyboard) { return m_keyboards[keyboard].m_config; } stx::init_mutex init; + +protected: + void ReleaseAllKeys(); + + KbInfo m_info; + std::vector m_keyboards; }; diff --git a/rpcs3/Input/basic_keyboard_handler.cpp b/rpcs3/Input/basic_keyboard_handler.cpp index 6c5f35117e..e7e2eb9ee4 100644 --- a/rpcs3/Input/basic_keyboard_handler.cpp +++ b/rpcs3/Input/basic_keyboard_handler.cpp @@ -62,13 +62,27 @@ bool basic_keyboard_handler::eventFilter(QObject* watched, QEvent* event) // !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target) if (!m_target || !m_target->isVisible() || watched == m_target) { - if (event->type() == QEvent::KeyPress) + switch (event->type()) + { + case QEvent::KeyPress: { keyPressEvent(static_cast(event)); + break; } - else if (event->type() == QEvent::KeyRelease) + case QEvent::KeyRelease: { keyReleaseEvent(static_cast(event)); + break; + } + case QEvent::FocusOut: + { + ReleaseAllKeys(); + break; + } + default: + { + break; + } } } return false;