Skip to content

Commit 8b0a150

Browse files
committed
Fix Input modifiers released condition
1 parent 7864ac8 commit 8b0a150

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

core/input/input_event.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_ma
578578
Key key_mask = (Key)(int64_t)key->get_modifiers_mask();
579579
if (key->is_pressed()) {
580580
match &= (action_mask & key_mask) == action_mask;
581+
} else {
582+
Key tmp = action_mask & key_mask;
583+
match |= (tmp == Key::SHIFT || tmp == Key::META || tmp == Key::CTRL || tmp == Key::ALT);
581584
}
582585
if (p_exact_match) {
583586
match &= action_mask == key_mask;

tests/core/input/test_input_event_key.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,47 @@ TEST_CASE("[InputEventKey] Key correctly stores and retrieves keycode with modif
7676
CHECK(key.get_physical_keycode_with_modifiers() != Key::SPACE);
7777
}
7878

79+
TEST_CASE("[InputEventKey] keycode and modifier matches") {
80+
InputEventKey spaceKeyAction;
81+
InputEventKey shiftKeyAction;
82+
InputEventKey shiftSpaceKeyAction;
83+
84+
spaceKeyAction.set_keycode(Key::SPACE);
85+
shiftKeyAction.set_keycode(Key::SHIFT);
86+
shiftKeyAction.set_shift_pressed(true);
87+
shiftSpaceKeyAction.set_keycode(Key::SPACE);
88+
shiftSpaceKeyAction.set_shift_pressed(true);
89+
90+
InputEventKey key;
91+
bool p_exact_match = false;
92+
float deadzone = 0.5;
93+
bool r_pressed = false;
94+
float r_strength = 0.0;
95+
float r_raw_strength = 0.0;
96+
97+
Ref<InputEventKey> p_event;
98+
99+
p_event = key.create_reference(Key::SPACE);
100+
p_event->set_pressed(true);
101+
CHECK(spaceKeyAction.action_match(p_event, p_exact_match, deadzone, &r_pressed, &r_strength, &r_raw_strength) == true);
102+
103+
p_event = key.create_reference(Key::SHIFT | KeyModifierMask::SHIFT);
104+
p_event->set_pressed(true);
105+
CHECK(shiftKeyAction.action_match(p_event, p_exact_match, deadzone, &r_pressed, &r_strength, &r_raw_strength) == true);
106+
107+
p_event = key.create_reference(Key::SPACE | KeyModifierMask::SHIFT);
108+
p_event->set_pressed(true);
109+
CHECK(shiftSpaceKeyAction.action_match(p_event, p_exact_match, deadzone, &r_pressed, &r_strength, &r_raw_strength) == true);
110+
111+
p_event = key.create_reference(Key::SHIFT | KeyModifierMask::SHIFT);
112+
p_event->set_pressed(false);
113+
CHECK(shiftKeyAction.action_match(p_event, p_exact_match, deadzone, &r_pressed, &r_strength, &r_raw_strength) == true);
114+
115+
p_event = key.create_reference(Key::SPACE);
116+
p_event->set_pressed(false);
117+
CHECK(spaceKeyAction.action_match(p_event, p_exact_match, deadzone, &r_pressed, &r_strength, &r_raw_strength) == true);
118+
}
119+
79120
TEST_CASE("[InputEventKey] Key correctly stores and retrieves unicode") {
80121
InputEventKey key;
81122

0 commit comments

Comments
 (0)