From 7b58340a60060cb75151a00bf7d2a8881e5f7b52 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 18 Mar 2026 09:49:17 +0100 Subject: [PATCH] Input: optimize keyboard button handling on release --- rpcs3/Input/keyboard_pad_handler.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 662b03c0a3..21c6b3c7e8 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -86,8 +86,6 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value) { const auto register_new_button_value = [code, pressed, value](Button& btn) -> u16 { - u16 actual_value = 0; - // Make sure we keep this button pressed until all related keys are released. if (pressed) { @@ -96,8 +94,16 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value) else { btn.m_pressed_keys.erase(code); + + // Optimization: just skip the whole combo parsing if there are no keys pressed + if (btn.m_pressed_keys.empty()) + { + return 0; + } } + u16 actual_value = 0; + // Get the max value of all pressed keys for this DS3 button for (const std::set& key_codes : btn.m_key_combos) { @@ -262,7 +268,7 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value) { const u16 actual_value = pressed ? MultipliedInput(value, is_left_stick ? l_stick_multiplier : r_stick_multiplier) : value; - const auto register_new_stick_value = [&](bool is_max) + const auto register_new_stick_value = [&](bool is_max) -> std::pair { const std::vector>& key_combos = is_max ? stick.m_key_combos_max : stick.m_key_combos_min; std::map& pressed_keys = is_max ? stick.m_pressed_keys_max : stick.m_pressed_keys_min;