From 6435c3d8509c7463142ec415c13ed97e76cf9635 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 29 Jun 2026 23:19:39 +0200 Subject: [PATCH] Remember which modifiers were present on key press and use them on key release This fixes an issue where a triggered command stays indefinitely active when the user releases the modifier before releasing the triggering key. --- input/keyboardinput.cpp | 12 +++++++++++- input/keyboardinput.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/input/keyboardinput.cpp b/input/keyboardinput.cpp index f9d83938..b8f5e823 100644 --- a/input/keyboardinput.cpp +++ b/input/keyboardinput.cpp @@ -308,11 +308,21 @@ keyboard_input::key( int const Key, int const Action ) { } // include active modifiers for currently pressed key, except if the key is a modifier itself - auto const key = + auto key = Key | ( modifier ? 0 : ( input::key_shift ? keymodifier::shift : 0 ) ) | ( modifier ? 0 : ( input::key_ctrl ? keymodifier::control : 0 ) ); + if( Action == GLFW_RELEASE ) { + auto const stored = m_modsforkeys.find( Key ); + if( stored != m_modsforkeys.end() ) { + key = stored->second; + } + m_modsforkeys.erase( Key ); + } else { + m_modsforkeys[ Key ] = key; + } + auto const lookup = m_bindings.find( key ); if( lookup == m_bindings.end() ) { // no binding for this key diff --git a/input/keyboardinput.h b/input/keyboardinput.h index fffa4630..1c1b5f2a 100644 --- a/input/keyboardinput.h +++ b/input/keyboardinput.h @@ -106,6 +106,7 @@ private: // members user_command m_command { user_command::none }; // last, if any, issued command usercommand_map m_bindings; + std::unordered_map m_modsforkeys; // modifiers that were used with the active keys command_relay m_relay; bindings_cache m_bindingscache; glm::vec2 m_movementhorizontal { 0.f };