summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-11-21 14:25:09 -0300
committerGitHub <noreply@github.com>2017-11-21 14:25:09 -0300
commit30dadb12281924ccb59efc8df4b3b9ee68c6e3a4 (patch)
tree3ce30ebc24eeaa39ba673d46d330673a838e99ad /core/os
parent20b07a1fb55c31d326c3f9c36d1276eb1bcf15e6 (diff)
parent524ffc971239e4826a2ee8e3df1d9af800ed5bba (diff)
Merge pull request #11933 from cxong/master
Use "Command" instead of "Meta" for macOS (#1619)
Diffstat (limited to 'core/os')
-rw-r--r--core/os/input_event.cpp8
-rw-r--r--core/os/keyboard.cpp43
-rw-r--r--core/os/keyboard.h1
3 files changed, 40 insertions, 12 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 103a8e82c2..3cdd9ae0e0 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -278,16 +278,16 @@ String InputEventKey::as_text() const {
return kc;
if (get_metakey()) {
- kc = "Meta+" + kc;
+ kc = find_keycode_name(KEY_META) + ("+" + kc);
}
if (get_alt()) {
- kc = "Alt+" + kc;
+ kc = find_keycode_name(KEY_ALT) + ("+" + kc);
}
if (get_shift()) {
- kc = "Shift+" + kc;
+ kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
}
if (get_control()) {
- kc = "Ctrl+" + kc;
+ kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
}
return kc;
}
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index edf4f3e2f9..dead3b6ac0 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -60,7 +60,11 @@ static const _KeyCodeText _keycodes[] = {
{KEY_PAGEDOWN ,"PageDown"},
{KEY_SHIFT ,"Shift"},
{KEY_CONTROL ,"Control"},
+#ifdef OSX_ENABLED
+ {KEY_META ,"Command"},
+#else
{KEY_META ,"Meta"},
+#endif
{KEY_ALT ,"Alt"},
{KEY_CAPSLOCK ,"CapsLock"},
{KEY_NUMLOCK ,"NumLock"},
@@ -390,14 +394,22 @@ bool keycode_has_unicode(uint32_t p_keycode) {
String keycode_get_string(uint32_t p_code) {
String codestr;
- if (p_code & KEY_MASK_SHIFT)
- codestr += "Shift+";
- if (p_code & KEY_MASK_ALT)
- codestr += "Alt+";
- if (p_code & KEY_MASK_CTRL)
- codestr += "Ctrl+";
- if (p_code & KEY_MASK_META)
- codestr += "Meta+";
+ if (p_code & KEY_MASK_SHIFT) {
+ codestr += find_keycode_name(KEY_SHIFT);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_ALT) {
+ codestr += find_keycode_name(KEY_ALT);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_CTRL) {
+ codestr += find_keycode_name(KEY_CONTROL);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_META) {
+ codestr += find_keycode_name(KEY_META);
+ codestr += "+";
+ }
p_code &= KEY_CODE_MASK;
@@ -433,6 +445,21 @@ int find_keycode(const String &p_code) {
return 0;
}
+const char *find_keycode_name(int p_keycode) {
+
+ const _KeyCodeText *kct = &_keycodes[0];
+
+ while (kct->text) {
+
+ if (kct->code == p_keycode) {
+ return kct->text;
+ }
+ kct++;
+ }
+
+ return "";
+}
+
struct _KeyCodeReplace {
int from;
int to;
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 509ff23a93..f49cbc6b18 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -326,6 +326,7 @@ enum KeyModifierMask {
String keycode_get_string(uint32_t p_code);
bool keycode_has_unicode(uint32_t p_keycode);
int find_keycode(const String &p_code);
+const char *find_keycode_name(int p_keycode);
int keycode_get_count();
int keycode_get_value_by_index(int p_index);
const char *keycode_get_name_by_index(int p_index);