diff --git a/rpcs3/Input/gui_pad_thread.cpp b/rpcs3/Input/gui_pad_thread.cpp index 4710af77ab..e467c9ae0a 100644 --- a/rpcs3/Input/gui_pad_thread.cpp +++ b/rpcs3/Input/gui_pad_thread.cpp @@ -109,9 +109,8 @@ bool gui_pad_thread::init() { m_handler.reset(); m_pad.reset(); + m_last_button_state.clear(); - // Initialize last button states as pressed to avoid unwanted button presses when starting the thread. - m_last_button_state.fill(true); m_timestamp = steady_clock::now(); m_initial_timestamp = steady_clock::now(); m_last_auto_repeat_button = pad_button::pad_button_max_enum; @@ -412,7 +411,18 @@ void gui_pad_thread::process_input() return; } - bool& last_state = m_last_button_state[static_cast(button_id)]; + if (!m_last_button_state.contains(button_id)) + { + // Ignore button presses and releases if there was no release detected at least once. + if (!pressed) + { + m_last_button_state[button_id] = false; + } + + return; + } + + bool& last_state = m_last_button_state[button_id]; if (pressed) { diff --git a/rpcs3/Input/gui_pad_thread.h b/rpcs3/Input/gui_pad_thread.h index 7c3503af1e..92140567c3 100644 --- a/rpcs3/Input/gui_pad_thread.h +++ b/rpcs3/Input/gui_pad_thread.h @@ -65,7 +65,7 @@ protected: atomic_t m_allow_global_input = false; static atomic_t m_reset; - std::array(pad_button::pad_button_max_enum)> m_last_button_state{}; + std::map m_last_button_state{}; steady_clock::time_point m_timestamp; steady_clock::time_point m_initial_timestamp;