1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Fix OS.find_keycode_from_string not working with modifiers

This commit is contained in:
Marcel Admiraal
2021-04-18 11:38:50 +01:00
parent 13f0158e49
commit 84199757a4
2 changed files with 26 additions and 5 deletions

View File

@@ -400,17 +400,38 @@ String keycode_get_string(Key p_code) {
return codestr; 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]; const _KeyCodeText *kct = &_keycodes[0];
while (kct->text) { while (kct->text) {
if (p_code.nocasecmp_to(kct->text) == 0) { if (last_part.nocasecmp_to(kct->text) == 0) {
return kct->code; keycode = kct->code;
break;
} }
kct++; 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) { const char *find_keycode_name(Key p_keycode) {

View File

@@ -330,7 +330,7 @@ constexpr KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
String keycode_get_string(Key p_code); String keycode_get_string(Key p_code);
bool keycode_has_unicode(Key p_keycode); bool keycode_has_unicode(Key p_keycode);
Key find_keycode(const String &p_code); Key find_keycode(const String &p_codestr);
const char *find_keycode_name(Key p_keycode); const char *find_keycode_name(Key p_keycode);
int keycode_get_count(); int keycode_get_count();
int keycode_get_value_by_index(int p_index); int keycode_get_value_by_index(int p_index);