From c4b2efd95eb8594a72d36f7745644a2561f83b4e Mon Sep 17 00:00:00 2001 From: RasmusNylander <43042651+rasmusnylander@users.noreply.github.com> Date: Thu, 16 Dec 2021 11:05:01 +0100 Subject: [PATCH] KeyboardMapper: Show multiple pressed keys at once When depressing a key, KeyboardMapperWidget::keydown_event() will now update only the pressed state of the button associated with the specific key, instead of also setting the pressed state of the all the buttons to false. This makes it possible to highlight multiple pressed keys at once and makes the code more consistent; the implementation of keyup_event implied that this was a feature of the program. --- .../KeyboardMapper/KeyboardMapperWidget.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index b0532b4503..ef6e6d846e 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -215,21 +215,24 @@ void KeyboardMapperWidget::save_to_file(StringView filename) void KeyboardMapperWidget::keydown_event(GUI::KeyEvent& event) { for (int i = 0; i < KEY_COUNT; i++) { + if (keys[i].scancode != event.scancode()) + continue; auto& tmp_button = m_keys.at(i); - tmp_button->set_pressed(keys[i].scancode == event.scancode()); + tmp_button->set_pressed(true); tmp_button->update(); + break; } } void KeyboardMapperWidget::keyup_event(GUI::KeyEvent& event) { for (int i = 0; i < KEY_COUNT; i++) { - if (keys[i].scancode == event.scancode()) { - auto& tmp_button = m_keys.at(i); - tmp_button->set_pressed(false); - tmp_button->update(); - break; - } + if (keys[i].scancode != event.scancode()) + continue; + auto& tmp_button = m_keys.at(i); + tmp_button->set_pressed(false); + tmp_button->update(); + break; } }