diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-19 15:39:06 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-19 15:39:06 +0200 |
commit | 92ca08311c2275bfe8e5554313a71a78d756d1e1 (patch) | |
tree | e52b2a585241f1f0c892b0c496d13c35c072e95f /core/os/keyboard.cpp | |
parent | 577fd2c24c9ad947a10c4d36bec7c95a7d1166fb (diff) | |
parent | 84199757a410ee68be0705e357b2a1f54b2842f7 (diff) | |
download | redot-engine-92ca08311c2275bfe8e5554313a71a78d756d1e1.tar.gz |
Merge pull request #47996 from madmiraal/fix-17430
Fix `OS.find_scancode_from_string()` not working with modifiers
Diffstat (limited to 'core/os/keyboard.cpp')
-rw-r--r-- | core/os/keyboard.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 1e32e6e096..1a51624030 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -400,17 +400,38 @@ String keycode_get_string(Key p_code) { return codestr; } -Key find_keycode(const String &p_code) { +Key find_keycode(const String &p_codestr) { + Key keycode = Key::NONE; + Vector<String> code_parts = p_codestr.split("+"); + if (code_parts.size() < 1) { + return keycode; + } + + String last_part = code_parts[code_parts.size() - 1]; const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { - if (p_code.nocasecmp_to(kct->text) == 0) { - return kct->code; + if (last_part.nocasecmp_to(kct->text) == 0) { + keycode = kct->code; + break; } kct++; } - return Key::NONE; + for (int part = 0; part < code_parts.size() - 1; part++) { + String code_part = code_parts[part]; + if (code_part.nocasecmp_to(find_keycode_name(Key::SHIFT)) == 0) { + keycode |= KeyModifierMask::SHIFT; + } else if (code_part.nocasecmp_to(find_keycode_name(Key::CTRL)) == 0) { + keycode |= KeyModifierMask::CTRL; + } else if (code_part.nocasecmp_to(find_keycode_name(Key::META)) == 0) { + keycode |= KeyModifierMask::META; + } else if (code_part.nocasecmp_to(find_keycode_name(Key::ALT)) == 0) { + keycode |= KeyModifierMask::ALT; + } + } + + return keycode; } const char *find_keycode_name(Key p_keycode) { |