diff options
author | Mel Collins <sigh@ambimist.com> | 2023-08-03 15:18:26 +0200 |
---|---|---|
committer | Mel Collins <sigh@ambimist.com> | 2024-01-26 14:42:28 +0100 |
commit | 8406e60522bb8d09649193be43c1c819edc1d059 (patch) | |
tree | 3c9ad2268b5c0c4ab50387e8d745528b2856daed /tests | |
parent | 4b6ad349886288405890b07d4a8da425eb3c97ec (diff) | |
download | redot-engine-8406e60522bb8d09649193be43c1c819edc1d059.tar.gz |
Add InputEventKey.location to tell left from right
This adds a new enum `KeyLocation` and associated property
`InputEventKey.location`, which indicates the left/right location of key
events which may come from one of two physical keys, eg. Shift, Ctrl.
It also adds simulation of missing Shift KEYUP events for Windows.
When multiple Shifts are held down at the same time, Windows natively
only sends a KEYUP for the last one to be released.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/input/test_input_event_key.h | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/tests/core/input/test_input_event_key.h b/tests/core/input/test_input_event_key.h index 3317941fad..80918542ce 100644 --- a/tests/core/input/test_input_event_key.h +++ b/tests/core/input/test_input_event_key.h @@ -85,6 +85,16 @@ TEST_CASE("[InputEventKey] Key correctly stores and retrieves unicode") { CHECK(key.get_unicode() != 'y'); } +TEST_CASE("[InputEventKey] Key correctly stores and retrieves location") { + InputEventKey key; + + CHECK(key.get_location() == KeyLocation::UNSPECIFIED); + + key.set_location(KeyLocation::LEFT); + CHECK(key.get_location() == KeyLocation::LEFT); + CHECK(key.get_location() != KeyLocation::RIGHT); +} + TEST_CASE("[InputEventKey] Key correctly stores and checks echo") { InputEventKey key; @@ -144,32 +154,36 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") { TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") { InputEventKey none_key; - CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, pressed=false, echo=false"); + CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, location=unspecified, pressed=false, echo=false"); // Set physical key to Escape. none_key.set_physical_keycode(Key::ESCAPE); - CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, pressed=false, echo=false"); + CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, location=unspecified, pressed=false, echo=false"); InputEventKey key; // Set physical to None, set keycode to Space. key.set_keycode(Key::SPACE); - CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=false, echo=false"); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=unspecified, pressed=false, echo=false"); + + // Set location + key.set_location(KeyLocation::RIGHT); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=false, echo=false"); // Set pressed to true. key.set_pressed(true); - CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=false"); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=false"); // set echo to true. key.set_echo(true); - CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=true"); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=true"); // Press Ctrl and Alt. key.set_ctrl_pressed(true); key.set_alt_pressed(true); #ifdef MACOS_ENABLED - CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, pressed=true, echo=true"); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, location=right, pressed=true, echo=true"); #else - CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, pressed=true, echo=true"); + CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, location=right, pressed=true, echo=true"); #endif } @@ -291,6 +305,34 @@ TEST_CASE("[IsMatch] Keys are correctly matched") { CHECK(key2.is_match(match, true) == true); CHECK(key2.is_match(no_match, true) == false); + + // Physical key with location. + InputEventKey key3; + key3.set_keycode(Key::NONE); + key3.set_physical_keycode(Key::SHIFT); + + Ref<InputEventKey> loc_ref = key.create_reference(Key::NONE); + + loc_ref->set_keycode(Key::SHIFT); + loc_ref->set_physical_keycode(Key::SHIFT); + + CHECK(key3.is_match(loc_ref, false) == true); + key3.set_location(KeyLocation::UNSPECIFIED); + CHECK(key3.is_match(loc_ref, false) == true); + + loc_ref->set_location(KeyLocation::LEFT); + CHECK(key3.is_match(loc_ref, false) == true); + + key3.set_location(KeyLocation::LEFT); + CHECK(key3.is_match(loc_ref, false) == true); + + key3.set_location(KeyLocation::RIGHT); + CHECK(key3.is_match(loc_ref, false) == false); + + // Keycode key with location. + key3.set_physical_keycode(Key::NONE); + key3.set_keycode(Key::SHIFT); + CHECK(key3.is_match(loc_ref, false) == true); } } // namespace TestInputEventKey |