Cleanup and unify keyboard input.

- Unify keycode values (secondary label printed on a key), remove unused hardcoded Latin-1 codes.
- Unify IME behaviour, add inline composition string display on Windows and X11.
- Add key_label (localized label printed on a key) value to the key events, and allow mapping actions to the unshifted Unicode events.
- Add support for physical keyboard (Bluetooth or Sidecar) handling on iOS.
- Add support for media key handling on macOS.

Co-authored-by: Raul Santos <raulsntos@gmail.com>
This commit is contained in:
bruvzg 2022-12-11 01:21:22 +02:00
parent 9937915ad7
commit daad4aed62
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
61 changed files with 4464 additions and 3655 deletions

View File

@ -85,7 +85,7 @@ jobs:
sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \
libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev \
libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm xvfb wget unzip \
llvm libspeechd-dev speech-dispatcher fontconfig libfontconfig-dev
llvm libspeechd-dev speech-dispatcher fontconfig libfontconfig-dev libxkbcommon-dev
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache

View File

@ -274,14 +274,9 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_7);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_8);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_9);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_L);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_R);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MENU);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_L);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_R);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HELP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_L);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_R);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACK);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, FORWARD);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STOP);
@ -289,11 +284,6 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEMUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEUP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSBOOST);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSUP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEUP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPLAY);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIASTOP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPREVIOUS);
@ -392,72 +382,12 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BAR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACERIGHT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIITILDE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOBREAKSPACE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAMDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CENT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STERLING);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CURRENCY);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YEN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BROKENBAR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SECTION);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COPYRIGHT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ORDFEMININE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTLEFT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOTSIGN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPHEN);
BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_REGISTERED, KEY_REGISTERED);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MACRON);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DEGREE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PLUSMINUS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TWOSUPERIOR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREESUPERIOR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MU);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARAGRAPH);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERIODCENTERED);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CEDILLA);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONESUPERIOR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MASCULINE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTRIGHT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEQUARTER);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEHALF);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREEQUARTERS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUESTIONDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AGRAVE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACIRCUMFLEX);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ATILDE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ADIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ARING);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CCEDILLA);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EGRAVE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ECIRCUMFLEX);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EDIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IGRAVE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ICIRCUMFLEX);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IDIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ETH);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NTILDE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OGRAVE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OCIRCUMFLEX);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OTILDE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ODIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MULTIPLY);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OOBLIQUE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UGRAVE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UCIRCUMFLEX);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UDIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YACUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THORN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SSHARP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIVISION);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YDIAERESIS);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GLOBE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KEYBOARD);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_EISU);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_KANA);
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK);
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK);

View File

@ -93,6 +93,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_anything_pressed"), &Input::is_anything_pressed);
ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed);
ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "keycode"), &Input::is_physical_key_pressed);
ClassDB::bind_method(D_METHOD("is_key_label_pressed", "keycode"), &Input::is_key_label_pressed);
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed);
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::is_action_pressed, DEFVAL(false));
@ -250,6 +251,11 @@ bool Input::is_physical_key_pressed(Key p_keycode) const {
return physical_keys_pressed.has(p_keycode);
}
bool Input::is_key_label_pressed(Key p_keycode) const {
_THREAD_SAFE_METHOD_
return key_label_pressed.has(p_keycode);
}
bool Input::is_mouse_button_pressed(MouseButton p_button) const {
_THREAD_SAFE_METHOD_
return mouse_button_mask.has_flag(mouse_button_to_mask(p_button));
@ -499,6 +505,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
physical_keys_pressed.erase(k->get_physical_keycode());
}
}
if (k.is_valid() && !k->is_echo() && k->get_key_label() != Key::NONE) {
if (k->is_pressed()) {
key_label_pressed.insert(k->get_key_label());
} else {
key_label_pressed.erase(k->get_key_label());
}
}
Ref<InputEventMouseButton> mb = p_event;
@ -919,6 +932,7 @@ void Input::release_pressed_events() {
keys_pressed.clear();
physical_keys_pressed.clear();
key_label_pressed.clear();
joy_buttons_pressed.clear();
_joy_axis.clear();

View File

@ -84,6 +84,7 @@ public:
private:
BitField<MouseButtonMask> mouse_button_mask;
RBSet<Key> key_label_pressed;
RBSet<Key> physical_keys_pressed;
RBSet<Key> keys_pressed;
RBSet<JoyButton> joy_buttons_pressed;
@ -247,6 +248,7 @@ public:
bool is_anything_pressed() const;
bool is_key_pressed(Key p_keycode) const;
bool is_physical_key_pressed(Key p_keycode) const;
bool is_key_label_pressed(Key p_keycode) const;
bool is_mouse_button_pressed(MouseButton p_button) const;
bool is_joy_button_pressed(int p_device, JoyButton p_button) const;
bool is_action_pressed(const StringName &p_action, bool p_exact = false) const;

View File

@ -285,6 +285,8 @@ void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_meta_pressed", "pressed"), &InputEventWithModifiers::set_meta_pressed);
ClassDB::bind_method(D_METHOD("is_meta_pressed"), &InputEventWithModifiers::is_meta_pressed);
ClassDB::bind_method(D_METHOD("get_modifiers_mask"), &InputEventWithModifiers::get_modifiers_mask);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_or_control_autoremap"), "set_command_or_control_autoremap", "is_command_or_control_autoremap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt_pressed"), "set_alt_pressed", "is_alt_pressed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift_pressed"), "set_shift_pressed", "is_shift_pressed");
@ -328,6 +330,15 @@ Key InputEventKey::get_keycode() const {
return keycode;
}
void InputEventKey::set_key_label(Key p_key_label) {
key_label = p_key_label;
emit_changed();
}
Key InputEventKey::get_key_label() const {
return key_label;
}
void InputEventKey::set_physical_keycode(Key p_keycode) {
physical_keycode = p_keycode;
emit_changed();
@ -363,13 +374,72 @@ Key InputEventKey::get_physical_keycode_with_modifiers() const {
return physical_keycode | (int64_t)get_modifiers_mask();
}
Key InputEventKey::get_key_label_with_modifiers() const {
return key_label | get_modifiers_mask();
}
String InputEventKey::as_text_physical_keycode() const {
String kc;
if (physical_keycode != Key::NONE) {
kc = keycode_get_string(physical_keycode);
} else {
kc = "(" + RTR("Unset") + ")";
}
if (kc.is_empty()) {
return kc;
}
String mods_text = InputEventWithModifiers::as_text();
return mods_text.is_empty() ? kc : mods_text + "+" + kc;
}
String InputEventKey::as_text_keycode() const {
String kc;
if (keycode != Key::NONE) {
kc = keycode_get_string(keycode);
} else {
kc = "(" + RTR("Unset") + ")";
}
if (kc.is_empty()) {
return kc;
}
String mods_text = InputEventWithModifiers::as_text();
return mods_text.is_empty() ? kc : mods_text + "+" + kc;
}
String InputEventKey::as_text_key_label() const {
String kc;
if (key_label != Key::NONE) {
kc = keycode_get_string(key_label);
} else {
kc = "(" + RTR("Unset") + ")";
}
if (kc.is_empty()) {
return kc;
}
String mods_text = InputEventWithModifiers::as_text();
return mods_text.is_empty() ? kc : mods_text + "+" + kc;
}
String InputEventKey::as_text() const {
String kc;
if (keycode == Key::NONE) {
if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
kc = keycode_get_string(key_label) + " (Unicode)";
} else if (keycode != Key::NONE) {
kc = keycode_get_string(keycode);
} else if (physical_keycode != Key::NONE) {
kc = keycode_get_string(physical_keycode) + " (" + RTR("Physical") + ")";
} else {
kc = keycode_get_string(keycode);
kc = "(" + RTR("Unset") + ")";
}
if (kc.is_empty()) {
@ -386,11 +456,16 @@ String InputEventKey::to_string() {
String kc = "";
String physical = "false";
if (keycode == Key::NONE) {
if (keycode == Key::NONE && physical_keycode == Key::NONE && unicode != 0) {
kc = "U+" + String::num_uint64(unicode, 16) + " (" + String::chr(unicode) + ")";
} else if (keycode != Key::NONE) {
kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")";
} else if (physical_keycode != Key::NONE) {
kc = itos((int64_t)physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")";
physical = "true";
} else {
kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")";
kc = "(" + RTR("Unset") + ")";
}
String mods = InputEventWithModifiers::as_text();
@ -403,6 +478,7 @@ Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) {
Ref<InputEventKey> ie;
ie.instantiate();
ie->set_keycode(p_keycode & KeyModifierMask::CODE_MASK);
ie->set_key_label(p_keycode & KeyModifierMask::CODE_MASK);
ie->set_unicode(char32_t(p_keycode & KeyModifierMask::CODE_MASK));
if ((p_keycode & KeyModifierMask::SHIFT) != Key::NONE) {
@ -435,11 +511,16 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_ma
}
bool match;
if (keycode != Key::NONE) {
if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
match = key_label == key->key_label;
} else if (keycode != Key::NONE) {
match = keycode == key->keycode;
} else if (physical_keycode != Key::NONE) {
match = physical_keycode == key->physical_keycode;
} else {
match = get_physical_keycode() == key->get_physical_keycode();
match = false;
}
Key action_mask = (Key)(int64_t)get_modifiers_mask();
Key key_mask = (Key)(int64_t)key->get_modifiers_mask();
if (key->is_pressed()) {
@ -470,12 +551,17 @@ bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match)
return false;
}
if (keycode == Key::NONE) {
return physical_keycode == key->physical_keycode &&
if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
return (key_label == key->key_label) &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
} else if (keycode != Key::NONE) {
return (keycode == key->keycode) &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
} else if (physical_keycode != Key::NONE) {
return (physical_keycode == key->physical_keycode) &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
} else {
return keycode == key->keycode &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
return false;
}
}
@ -488,6 +574,9 @@ void InputEventKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode);
ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode);
ClassDB::bind_method(D_METHOD("set_key_label", "key_label"), &InputEventKey::set_key_label);
ClassDB::bind_method(D_METHOD("get_key_label"), &InputEventKey::get_key_label);
ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
@ -495,10 +584,16 @@ void InputEventKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers);
ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers);
ClassDB::bind_method(D_METHOD("get_key_label_with_modifiers"), &InputEventKey::get_key_label_with_modifiers);
ClassDB::bind_method(D_METHOD("as_text_keycode"), &InputEventKey::as_text_keycode);
ClassDB::bind_method(D_METHOD("as_text_physical_keycode"), &InputEventKey::as_text_physical_keycode);
ClassDB::bind_method(D_METHOD("as_text_key_label"), &InputEventKey::as_text_key_label);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "key_label"), "set_key_label", "get_key_label");
ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
}

View File

@ -153,6 +153,7 @@ class InputEventKey : public InputEventWithModifiers {
Key keycode = Key::NONE; // Key enum, without modifier masks.
Key physical_keycode = Key::NONE;
Key key_label = Key::NONE;
uint32_t unicode = 0; ///unicode
bool echo = false; /// true if this is an echo key
@ -170,6 +171,9 @@ public:
void set_physical_keycode(Key p_keycode);
Key get_physical_keycode() const;
void set_key_label(Key p_key_label);
Key get_key_label() const;
void set_unicode(char32_t p_unicode);
char32_t get_unicode() const;
@ -178,12 +182,16 @@ public:
Key get_keycode_with_modifiers() const;
Key get_physical_keycode_with_modifiers() const;
Key get_key_label_with_modifiers() const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text_physical_keycode() const;
virtual String as_text_keycode() const;
virtual String as_text_key_label() const;
virtual String as_text() const override;
virtual String to_string() override;

View File

@ -127,14 +127,9 @@ static const _KeyCodeText _keycodes[] = {
{Key::KP_7 ,"Kp 7"},
{Key::KP_8 ,"Kp 8"},
{Key::KP_9 ,"Kp 9"},
{Key::SUPER_L ,"Super L"},
{Key::SUPER_R ,"Super R"},
{Key::MENU ,"Menu"},
{Key::HYPER_L ,"Hyper L"},
{Key::HYPER_R ,"Hyper R"},
{Key::HYPER ,"Hyper"},
{Key::HELP ,"Help"},
{Key::DIRECTION_L ,"Direction L"},
{Key::DIRECTION_R ,"Direction R"},
{Key::BACK ,"Back"},
{Key::FORWARD ,"Forward"},
{Key::STOP ,"Stop"},
@ -142,11 +137,6 @@ static const _KeyCodeText _keycodes[] = {
{Key::VOLUMEDOWN ,"VolumeDown"},
{Key::VOLUMEMUTE ,"VolumeMute"},
{Key::VOLUMEUP ,"VolumeUp"},
{Key::BASSBOOST ,"BassBoost"},
{Key::BASSUP ,"BassUp"},
{Key::BASSDOWN ,"BassDown"},
{Key::TREBLEUP ,"TrebleUp"},
{Key::TREBLEDOWN ,"TrebleDown"},
{Key::MEDIAPLAY ,"MediaPlay"},
{Key::MEDIASTOP ,"MediaStop"},
{Key::MEDIAPREVIOUS ,"MediaPrevious"},
@ -174,6 +164,10 @@ static const _KeyCodeText _keycodes[] = {
{Key::LAUNCHD ,"LaunchD"},
{Key::LAUNCHE ,"LaunchE"},
{Key::LAUNCHF ,"LaunchF"},
{Key::GLOBE ,"Globe"},
{Key::KEYBOARD ,"On-screen keyboard"},
{Key::JIS_EISU ,"JIS Eisu"},
{Key::JIS_KANA ,"JIS Kana"},
{Key::UNKNOWN ,"Unknown"},
{Key::SPACE ,"Space"},
{Key::EXCLAM ,"Exclam"},
@ -244,72 +238,6 @@ static const _KeyCodeText _keycodes[] = {
{Key::BAR ,"Bar"},
{Key::BRACERIGHT ,"BraceRight"},
{Key::ASCIITILDE ,"AsciiTilde"},
{Key::NOBREAKSPACE ,"NoBreakSpace"},
{Key::EXCLAMDOWN ,"ExclamDown"},
{Key::CENT ,"Cent"},
{Key::STERLING ,"Sterling"},
{Key::CURRENCY ,"Currency"},
{Key::YEN ,"Yen"},
{Key::BROKENBAR ,"BrokenBar"},
{Key::SECTION ,"Section"},
{Key::DIAERESIS ,"Diaeresis"},
{Key::COPYRIGHT ,"Copyright"},
{Key::ORDFEMININE ,"Ordfeminine"},
{Key::GUILLEMOTLEFT ,"GuillemotLeft"},
{Key::NOTSIGN ,"NotSign"},
{Key::HYPHEN ,"Hyphen"},
{Key::KEY_REGISTERED ,"Registered"},
{Key::MACRON ,"Macron"},
{Key::DEGREE ,"Degree"},
{Key::PLUSMINUS ,"PlusMinus"},
{Key::TWOSUPERIOR ,"TwoSuperior"},
{Key::THREESUPERIOR ,"ThreeSuperior"},
{Key::ACUTE ,"Acute"},
{Key::MU ,"Mu"},
{Key::PARAGRAPH ,"Paragraph"},
{Key::PERIODCENTERED ,"PeriodCentered"},
{Key::CEDILLA ,"Cedilla"},
{Key::ONESUPERIOR ,"OneSuperior"},
{Key::MASCULINE ,"Masculine"},
{Key::GUILLEMOTRIGHT ,"GuillemotRight"},
{Key::ONEQUARTER ,"OneQuarter"},
{Key::ONEHALF ,"OneHalf"},
{Key::THREEQUARTERS ,"ThreeQuarters"},
{Key::QUESTIONDOWN ,"QuestionDown"},
{Key::AGRAVE ,"Agrave"},
{Key::AACUTE ,"Aacute"},
{Key::ACIRCUMFLEX ,"AcircumFlex"},
{Key::ATILDE ,"Atilde"},
{Key::ADIAERESIS ,"Adiaeresis"},
{Key::ARING ,"Aring"},
{Key::AE ,"Ae"},
{Key::CCEDILLA ,"Ccedilla"},
{Key::EGRAVE ,"Egrave"},
{Key::EACUTE ,"Eacute"},
{Key::ECIRCUMFLEX ,"Ecircumflex"},
{Key::EDIAERESIS ,"Ediaeresis"},
{Key::IGRAVE ,"Igrave"},
{Key::IACUTE ,"Iacute"},
{Key::ICIRCUMFLEX ,"Icircumflex"},
{Key::IDIAERESIS ,"Idiaeresis"},
{Key::ETH ,"Eth"},
{Key::NTILDE ,"Ntilde"},
{Key::OGRAVE ,"Ograve"},
{Key::OACUTE ,"Oacute"},
{Key::OCIRCUMFLEX ,"Ocircumflex"},
{Key::OTILDE ,"Otilde"},
{Key::ODIAERESIS ,"Odiaeresis"},
{Key::MULTIPLY ,"Multiply"},
{Key::OOBLIQUE ,"Ooblique"},
{Key::UGRAVE ,"Ugrave"},
{Key::UACUTE ,"Uacute"},
{Key::UCIRCUMFLEX ,"Ucircumflex"},
{Key::UDIAERESIS ,"Udiaeresis"},
{Key::YACUTE ,"Yacute"},
{Key::THORN ,"Thorn"},
{Key::SSHARP ,"Ssharp"},
{Key::DIVISION ,"Division"},
{Key::YDIAERESIS ,"Ydiaeresis"},
{Key::NONE ,nullptr}
/* clang-format on */
};
@ -378,14 +306,9 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::F33:
case Key::F34:
case Key::F35:
case Key::SUPER_L:
case Key::SUPER_R:
case Key::MENU:
case Key::HYPER_L:
case Key::HYPER_R:
case Key::HYPER:
case Key::HELP:
case Key::DIRECTION_L:
case Key::DIRECTION_R:
case Key::BACK:
case Key::FORWARD:
case Key::STOP:
@ -393,11 +316,6 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::VOLUMEDOWN:
case Key::VOLUMEMUTE:
case Key::VOLUMEUP:
case Key::BASSBOOST:
case Key::BASSUP:
case Key::BASSDOWN:
case Key::TREBLEUP:
case Key::TREBLEDOWN:
case Key::MEDIAPLAY:
case Key::MEDIASTOP:
case Key::MEDIAPREVIOUS:
@ -426,6 +344,10 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::LAUNCHD:
case Key::LAUNCHE:
case Key::LAUNCHF:
case Key::GLOBE:
case Key::KEYBOARD:
case Key::JIS_EISU:
case Key::JIS_KANA:
return false;
default: {
}
@ -522,3 +444,24 @@ int keycode_get_value_by_index(int p_index) {
const char *keycode_get_name_by_index(int p_index) {
return _keycodes[p_index].text;
}
char32_t fix_unicode(char32_t p_char) {
if (p_char >= 0x20 && p_char != 0x7F) {
return p_char;
}
return 0;
}
Key fix_keycode(char32_t p_char, Key p_key) {
if (p_char >= 0x20 && p_char <= 0x7E) {
return (Key)String::char_uppercase(p_char);
}
return p_key;
}
Key fix_key_label(char32_t p_char, Key p_key) {
if (p_char >= 0x20 && p_char != 0x7F) {
return (Key)String::char_uppercase(p_char);
}
return p_key;
}

View File

@ -127,11 +127,8 @@ enum class Key {
SUPER_L = SPECIAL | 0x40,
SUPER_R = SPECIAL | 0x41,
MENU = SPECIAL | 0x42,
HYPER_L = SPECIAL | 0x43,
HYPER_R = SPECIAL | 0x44,
HYPER = SPECIAL | 0x43,
HELP = SPECIAL | 0x45,
DIRECTION_L = SPECIAL | 0x46,
DIRECTION_R = SPECIAL | 0x47,
BACK = SPECIAL | 0x48,
FORWARD = SPECIAL | 0x49,
STOP = SPECIAL | 0x4A,
@ -139,11 +136,6 @@ enum class Key {
VOLUMEDOWN = SPECIAL | 0x4C,
VOLUMEMUTE = SPECIAL | 0x4D,
VOLUMEUP = SPECIAL | 0x4E,
BASSBOOST = SPECIAL | 0x4F,
BASSUP = SPECIAL | 0x50,
BASSDOWN = SPECIAL | 0x51,
TREBLEUP = SPECIAL | 0x52,
TREBLEDOWN = SPECIAL | 0x53,
MEDIAPLAY = SPECIAL | 0x54,
MEDIASTOP = SPECIAL | 0x55,
MEDIAPREVIOUS = SPECIAL | 0x56,
@ -173,7 +165,12 @@ enum class Key {
LAUNCHE = SPECIAL | 0x6E,
LAUNCHF = SPECIAL | 0x6F,
UNKNOWN = SPECIAL | 0xFFFFFF,
GLOBE = SPECIAL | 0x70,
KEYBOARD = SPECIAL | 0x71,
JIS_EISU = SPECIAL | 0x72,
JIS_KANA = SPECIAL | 0x73,
UNKNOWN = SPECIAL | 0x7FFFFF,
/* PRINTABLE LATIN 1 CODES */
@ -246,74 +243,8 @@ enum class Key {
BAR = 0x007C,
BRACERIGHT = 0x007D,
ASCIITILDE = 0x007E,
NOBREAKSPACE = 0x00A0,
EXCLAMDOWN = 0x00A1,
CENT = 0x00A2,
STERLING = 0x00A3,
CURRENCY = 0x00A4,
YEN = 0x00A5,
BROKENBAR = 0x00A6,
SECTION = 0x00A7,
DIAERESIS = 0x00A8,
COPYRIGHT = 0x00A9,
ORDFEMININE = 0x00AA,
GUILLEMOTLEFT = 0x00AB,
NOTSIGN = 0x00AC,
HYPHEN = 0x00AD,
KEY_REGISTERED = 0x00AE, // "REGISTERED" is a reserved word on Windows.
MACRON = 0x00AF,
DEGREE = 0x00B0,
PLUSMINUS = 0x00B1,
TWOSUPERIOR = 0x00B2,
THREESUPERIOR = 0x00B3,
ACUTE = 0x00B4,
MU = 0x00B5,
PARAGRAPH = 0x00B6,
PERIODCENTERED = 0x00B7,
CEDILLA = 0x00B8,
ONESUPERIOR = 0x00B9,
MASCULINE = 0x00BA,
GUILLEMOTRIGHT = 0x00BB,
ONEQUARTER = 0x00BC,
ONEHALF = 0x00BD,
THREEQUARTERS = 0x00BE,
QUESTIONDOWN = 0x00BF,
AGRAVE = 0x00C0,
AACUTE = 0x00C1,
ACIRCUMFLEX = 0x00C2,
ATILDE = 0x00C3,
ADIAERESIS = 0x00C4,
ARING = 0x00C5,
AE = 0x00C6,
CCEDILLA = 0x00C7,
EGRAVE = 0x00C8,
EACUTE = 0x00C9,
ECIRCUMFLEX = 0x00CA,
EDIAERESIS = 0x00CB,
IGRAVE = 0x00CC,
IACUTE = 0x00CD,
ICIRCUMFLEX = 0x00CE,
IDIAERESIS = 0x00CF,
ETH = 0x00D0,
NTILDE = 0x00D1,
OGRAVE = 0x00D2,
OACUTE = 0x00D3,
OCIRCUMFLEX = 0x00D4,
OTILDE = 0x00D5,
ODIAERESIS = 0x00D6,
MULTIPLY = 0x00D7,
OOBLIQUE = 0x00D8,
UGRAVE = 0x00D9,
UACUTE = 0x00DA,
UCIRCUMFLEX = 0x00DB,
UDIAERESIS = 0x00DC,
YACUTE = 0x00DD,
THORN = 0x00DE,
SSHARP = 0x00DF,
DIVISION = 0x00F7,
YDIAERESIS = 0x00FF,
END_LATIN1 = 0x0100,
};
enum class KeyModifierMask {
@ -407,4 +338,8 @@ int keycode_get_count();
int keycode_get_value_by_index(int p_index);
const char *keycode_get_name_by_index(int p_index);
char32_t fix_unicode(char32_t p_char);
Key fix_keycode(char32_t p_char, Key p_key);
Key fix_key_label(char32_t p_char, Key p_key);
#endif // KEYBOARD_H

View File

@ -1767,30 +1767,15 @@
<constant name="KEY_KP_9" value="4194447" enum="Key">
Number 9 on the numeric keypad.
</constant>
<constant name="KEY_SUPER_L" value="4194368" enum="Key">
Left Super key (Windows key).
</constant>
<constant name="KEY_SUPER_R" value="4194369" enum="Key">
Right Super key (Windows key).
</constant>
<constant name="KEY_MENU" value="4194370" enum="Key">
Context menu key.
</constant>
<constant name="KEY_HYPER_L" value="4194371" enum="Key">
Left Hyper key.
</constant>
<constant name="KEY_HYPER_R" value="4194372" enum="Key">
Right Hyper key.
<constant name="KEY_HYPER" value="4194371" enum="Key">
Hyper key. (On Linux/X11 only).
</constant>
<constant name="KEY_HELP" value="4194373" enum="Key">
Help key.
</constant>
<constant name="KEY_DIRECTION_L" value="4194374" enum="Key">
Left Direction key.
</constant>
<constant name="KEY_DIRECTION_R" value="4194375" enum="Key">
Right Direction key.
</constant>
<constant name="KEY_BACK" value="4194376" enum="Key">
Media back key. Not to be confused with the Back button on an Android device.
</constant>
@ -1812,21 +1797,6 @@
<constant name="KEY_VOLUMEUP" value="4194382" enum="Key">
Volume up key.
</constant>
<constant name="KEY_BASSBOOST" value="4194383" enum="Key">
Bass Boost key.
</constant>
<constant name="KEY_BASSUP" value="4194384" enum="Key">
Bass up key.
</constant>
<constant name="KEY_BASSDOWN" value="4194385" enum="Key">
Bass down key.
</constant>
<constant name="KEY_TREBLEUP" value="4194386" enum="Key">
Treble up key.
</constant>
<constant name="KEY_TREBLEDOWN" value="4194387" enum="Key">
Treble down key.
</constant>
<constant name="KEY_MEDIAPLAY" value="4194388" enum="Key">
Media play key.
</constant>
@ -1911,7 +1881,7 @@
<constant name="KEY_LAUNCHF" value="4194415" enum="Key">
Launch Shortcut F key.
</constant>
<constant name="KEY_UNKNOWN" value="16777215" enum="Key">
<constant name="KEY_UNKNOWN" value="8388607" enum="Key">
Unknown key.
</constant>
<constant name="KEY_SPACE" value="32" enum="Key">
@ -2121,203 +2091,23 @@
<constant name="KEY_ASCIITILDE" value="126" enum="Key">
~ key.
</constant>
<constant name="KEY_NOBREAKSPACE" value="160" enum="Key">
Non-breakable space key.
</constant>
<constant name="KEY_EXCLAMDOWN" value="161" enum="Key">
¡ key.
</constant>
<constant name="KEY_CENT" value="162" enum="Key">
¢ key.
</constant>
<constant name="KEY_STERLING" value="163" enum="Key">
£ key.
</constant>
<constant name="KEY_CURRENCY" value="164" enum="Key">
¤ key.
</constant>
<constant name="KEY_YEN" value="165" enum="Key">
¥ key.
</constant>
<constant name="KEY_BROKENBAR" value="166" enum="Key">
¦ key.
</constant>
<constant name="KEY_SECTION" value="167" enum="Key">
§ key.
</constant>
<constant name="KEY_DIAERESIS" value="168" enum="Key">
¨ key.
<constant name="KEY_GLOBE" value="4194416" enum="Key">
"Globe" key on Mac / iPad keyboard.
</constant>
<constant name="KEY_COPYRIGHT" value="169" enum="Key">
© key.
<constant name="KEY_KEYBOARD" value="4194417" enum="Key">
"On-screen keyboard" key iPad keyboard.
</constant>
<constant name="KEY_ORDFEMININE" value="170" enum="Key">
ª key.
<constant name="KEY_JIS_EISU" value="4194418" enum="Key">
英数 key on Mac keyboard.
</constant>
<constant name="KEY_GUILLEMOTLEFT" value="171" enum="Key">
« key.
</constant>
<constant name="KEY_NOTSIGN" value="172" enum="Key">
¬ key.
</constant>
<constant name="KEY_HYPHEN" value="173" enum="Key">
Soft hyphen key.
</constant>
<constant name="KEY_REGISTERED" value="174" enum="Key">
® key.
</constant>
<constant name="KEY_MACRON" value="175" enum="Key">
¯ key.
</constant>
<constant name="KEY_DEGREE" value="176" enum="Key">
° key.
</constant>
<constant name="KEY_PLUSMINUS" value="177" enum="Key">
± key.
</constant>
<constant name="KEY_TWOSUPERIOR" value="178" enum="Key">
² key.
</constant>
<constant name="KEY_THREESUPERIOR" value="179" enum="Key">
³ key.
</constant>
<constant name="KEY_ACUTE" value="180" enum="Key">
´ key.
</constant>
<constant name="KEY_MU" value="181" enum="Key">
µ key.
</constant>
<constant name="KEY_PARAGRAPH" value="182" enum="Key">
¶ key.
</constant>
<constant name="KEY_PERIODCENTERED" value="183" enum="Key">
· key.
</constant>
<constant name="KEY_CEDILLA" value="184" enum="Key">
¸ key.
</constant>
<constant name="KEY_ONESUPERIOR" value="185" enum="Key">
¹ key.
</constant>
<constant name="KEY_MASCULINE" value="186" enum="Key">
º key.
</constant>
<constant name="KEY_GUILLEMOTRIGHT" value="187" enum="Key">
» key.
</constant>
<constant name="KEY_ONEQUARTER" value="188" enum="Key">
¼ key.
</constant>
<constant name="KEY_ONEHALF" value="189" enum="Key">
½ key.
</constant>
<constant name="KEY_THREEQUARTERS" value="190" enum="Key">
¾ key.
</constant>
<constant name="KEY_QUESTIONDOWN" value="191" enum="Key">
¿ key.
</constant>
<constant name="KEY_AGRAVE" value="192" enum="Key">
À key.
</constant>
<constant name="KEY_AACUTE" value="193" enum="Key">
Á key.
</constant>
<constant name="KEY_ACIRCUMFLEX" value="194" enum="Key">
 key.
</constant>
<constant name="KEY_ATILDE" value="195" enum="Key">
à key.
</constant>
<constant name="KEY_ADIAERESIS" value="196" enum="Key">
Ä key.
</constant>
<constant name="KEY_ARING" value="197" enum="Key">
Å key.
</constant>
<constant name="KEY_AE" value="198" enum="Key">
Æ key.
</constant>
<constant name="KEY_CCEDILLA" value="199" enum="Key">
Ç key.
</constant>
<constant name="KEY_EGRAVE" value="200" enum="Key">
È key.
</constant>
<constant name="KEY_EACUTE" value="201" enum="Key">
É key.
</constant>
<constant name="KEY_ECIRCUMFLEX" value="202" enum="Key">
Ê key.
</constant>
<constant name="KEY_EDIAERESIS" value="203" enum="Key">
Ë key.
</constant>
<constant name="KEY_IGRAVE" value="204" enum="Key">
Ì key.
</constant>
<constant name="KEY_IACUTE" value="205" enum="Key">
Í key.
</constant>
<constant name="KEY_ICIRCUMFLEX" value="206" enum="Key">
Î key.
</constant>
<constant name="KEY_IDIAERESIS" value="207" enum="Key">
Ï key.
</constant>
<constant name="KEY_ETH" value="208" enum="Key">
Ð key.
</constant>
<constant name="KEY_NTILDE" value="209" enum="Key">
Ñ key.
</constant>
<constant name="KEY_OGRAVE" value="210" enum="Key">
Ò key.
</constant>
<constant name="KEY_OACUTE" value="211" enum="Key">
Ó key.
</constant>
<constant name="KEY_OCIRCUMFLEX" value="212" enum="Key">
Ô key.
</constant>
<constant name="KEY_OTILDE" value="213" enum="Key">
Õ key.
</constant>
<constant name="KEY_ODIAERESIS" value="214" enum="Key">
Ö key.
</constant>
<constant name="KEY_MULTIPLY" value="215" enum="Key">
× key.
</constant>
<constant name="KEY_OOBLIQUE" value="216" enum="Key">
Ø key.
</constant>
<constant name="KEY_UGRAVE" value="217" enum="Key">
Ù key.
</constant>
<constant name="KEY_UACUTE" value="218" enum="Key">
Ú key.
</constant>
<constant name="KEY_UCIRCUMFLEX" value="219" enum="Key">
Û key.
</constant>
<constant name="KEY_UDIAERESIS" value="220" enum="Key">
Ü key.
</constant>
<constant name="KEY_YACUTE" value="221" enum="Key">
Ý key.
</constant>
<constant name="KEY_THORN" value="222" enum="Key">
Þ key.
</constant>
<constant name="KEY_SSHARP" value="223" enum="Key">
ß key.
</constant>
<constant name="KEY_DIVISION" value="247" enum="Key">
÷ key.
</constant>
<constant name="KEY_YDIAERESIS" value="255" enum="Key">
ÿ key.
<constant name="KEY_JIS_KANA" value="4194419" enum="Key">
かな key on Mac keyboard.
</constant>
<constant name="KEY_CODE_MASK" value="8388607" enum="KeyModifierMask" is_bitfield="true">
Key Code mask.

View File

@ -224,11 +224,18 @@
Returns [code]true[/code] if the system knows the specified device. This means that it sets all button and axis indices. Unknown joypads are not expected to match these constants, but you can still retrieve events from them.
</description>
</method>
<method name="is_key_label_pressed" qualifiers="const">
<return type="bool" />
<param index="0" name="keycode" type="int" enum="Key" />
<description>
Returns [code]true[/code] if you are pressing the key with the [param keycode] printed on it. You can pass a [enum Key] constant or any Unicode character code.
</description>
</method>
<method name="is_key_pressed" qualifiers="const">
<return type="bool" />
<param index="0" name="keycode" type="int" enum="Key" />
<description>
Returns [code]true[/code] if you are pressing the key in the current keyboard layout. You can pass a [enum Key] constant.
Returns [code]true[/code] if you are pressing the Latin key in the current keyboard layout. You can pass a [enum Key] constant.
[method is_key_pressed] is only recommended over [method is_physical_key_pressed] in non-game applications. This ensures that shortcut keys behave as expected depending on the user's keyboard layout, as keyboard shortcuts are generally dependent on the keyboard layout in non-game applications. If in doubt, use [method is_physical_key_pressed].
[b]Note:[/b] Due to keyboard ghosting, [method is_key_pressed] may return [code]false[/code] even if one of the action's keys is pressed. See [url=$DOCS_URL/tutorials/inputs/input_examples.html#keyboard-events]Input examples[/url] in the documentation for more information.
</description>

View File

@ -5,15 +5,42 @@
</brief_description>
<description>
Stores key presses on the keyboard. Supports key presses, key releases and [member echo] events.
[b]Note:[/b] Events received from the keyboard usually have all properties set. Event mappings should have only one of the [member keycode], [member physical_keycode] or [member unicode] set.
When events are compared, properties are checked in the following priority - [member keycode], [member physical_keycode] and [member unicode], events with the first matching value will be considered equal.
</description>
<tutorials>
<link title="InputEvent">$DOCS_URL/tutorials/inputs/inputevent.html</link>
</tutorials>
<methods>
<method name="as_text_key_label" qualifiers="const">
<return type="String" />
<description>
Returns a [String] representation of the event's [member key_label] and modifiers.
</description>
</method>
<method name="as_text_keycode" qualifiers="const">
<return type="String" />
<description>
Returns a [String] representation of the event's [member keycode] and modifiers.
</description>
</method>
<method name="as_text_physical_keycode" qualifiers="const">
<return type="String" />
<description>
Returns a [String] representation of the event's [member physical_keycode] and modifiers.
</description>
</method>
<method name="get_key_label_with_modifiers" qualifiers="const">
<return type="int" enum="Key" />
<description>
Returns the localized key label combined with modifier keys such as [kbd]Shift[/kbd] or [kbd]Alt[/kbd]. See also [InputEventWithModifiers].
To get a human-readable representation of the [InputEventKey] with modifiers, use [code]OS.get_keycode_string(event.get_key_label_with_modifiers())[/code] where [code]event[/code] is the [InputEventKey].
</description>
</method>
<method name="get_keycode_with_modifiers" qualifiers="const">
<return type="int" enum="Key" />
<description>
Returns the keycode combined with modifier keys such as [kbd]Shift[/kbd] or [kbd]Alt[/kbd]. See also [InputEventWithModifiers].
Returns the Latin keycode combined with modifier keys such as [kbd]Shift[/kbd] or [kbd]Alt[/kbd]. See also [InputEventWithModifiers].
To get a human-readable representation of the [InputEventKey] with modifiers, use [code]OS.get_keycode_string(event.get_keycode_with_modifiers())[/code] where [code]event[/code] is the [InputEventKey].
</description>
</method>
@ -29,19 +56,36 @@
<member name="echo" type="bool" setter="set_echo" getter="is_echo" default="false">
If [code]true[/code], the key was already pressed before this event. It means the user is holding the key down.
</member>
<member name="key_label" type="int" setter="set_key_label" getter="get_key_label" enum="Key" default="0">
Represents the localized label printed on the key in the current keyboard layout, which corresponds to one of the [enum Key] constants or any valid Unicode character.
For keyboard layouts with a single label on the key, it is equivalent to [member keycode].
To get a human-readable representation of the [InputEventKey], use [code]OS.get_keycode_string(event.key_label)[/code] where [code]event[/code] is the [InputEventKey].
[codeblock]
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
[/codeblock]
</member>
<member name="keycode" type="int" setter="set_keycode" getter="get_keycode" enum="Key" default="0">
The key keycode, which corresponds to one of the [enum Key] constants. Represent key in the current keyboard layout.
Latin label printed on the key in the current keyboard layout, which corresponds to one of the [enum Key] constants.
To get a human-readable representation of the [InputEventKey], use [code]OS.get_keycode_string(event.keycode)[/code] where [code]event[/code] is the [InputEventKey].
[codeblock]
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
[/codeblock]
</member>
<member name="physical_keycode" type="int" setter="set_physical_keycode" getter="get_physical_keycode" enum="Key" default="0">
Key physical keycode, which corresponds to one of the [enum Key] constants. Represent the physical location of a key on the 101/102-key US QWERTY keyboard.
Represents the physical location of a key on the 101/102-key US QWERTY keyboard, which corresponds to one of the [enum Key] constants.
To get a human-readable representation of the [InputEventKey], use [code]OS.get_keycode_string(event.keycode)[/code] where [code]event[/code] is the [InputEventKey].
</member>
<member name="pressed" type="bool" setter="set_pressed" getter="is_pressed" default="false">
If [code]true[/code], the key's state is pressed. If [code]false[/code], the key's state is released.
</member>
<member name="unicode" type="int" setter="set_unicode" getter="get_unicode" default="0">
The key Unicode identifier (when relevant). Unicode identifiers for the composite characters and complex scripts may not be available unless IME input mode is active. See [method Window.set_ime_active] for more information.
The key Unicode character code (when relevant), shifted by modifier keys. Unicode character codes for composite characters and complex scripts may not be available unless IME input mode is active. See [method Window.set_ime_active] for more information.
</member>
</members>
</class>

View File

@ -10,6 +10,12 @@
<link title="InputEvent">$DOCS_URL/tutorials/inputs/inputevent.html</link>
</tutorials>
<methods>
<method name="get_modifiers_mask" qualifiers="const">
<return type="int" enum="KeyModifierMask" />
<description>
Returns the keycode combination of modifier keys.
</description>
</method>
<method name="is_command_or_control_pressed" qualifiers="const">
<return type="bool" />
<description>

View File

@ -449,10 +449,14 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
// First Column - Icon
Ref<InputEventKey> k = event;
if (k.is_valid()) {
if (k->get_physical_keycode() == Key::NONE) {
if (k->get_physical_keycode() == Key::NONE && k->get_keycode() == Key::NONE && k->get_key_label() != Key::NONE) {
event_item->set_icon(0, action_tree->get_theme_icon(SNAME("KeyboardLabel"), SNAME("EditorIcons")));
} else if (k->get_keycode() != Key::NONE) {
event_item->set_icon(0, action_tree->get_theme_icon(SNAME("Keyboard"), SNAME("EditorIcons")));
} else {
} else if (k->get_physical_keycode() != Key::NONE) {
event_item->set_icon(0, action_tree->get_theme_icon(SNAME("KeyboardPhysical"), SNAME("EditorIcons")));
} else {
event_item->set_icon(0, action_tree->get_theme_icon(SNAME("KeyboardError"), SNAME("EditorIcons")));
}
}

View File

@ -59,16 +59,42 @@ static const char *_joy_axis_descriptions[(size_t)JoyAxis::MAX * 2] = {
String EventListenerLineEdit::get_event_text(const Ref<InputEvent> &p_event, bool p_include_device) {
ERR_FAIL_COND_V_MSG(p_event.is_null(), String(), "Provided event is not a valid instance of InputEvent");
String text = p_event->as_text();
String text;
Ref<InputEventKey> key = p_event;
if (key.is_valid() && key->is_command_or_control_autoremap()) {
if (key.is_valid()) {
String mods_text = key->InputEventWithModifiers::as_text();
mods_text = mods_text.is_empty() ? mods_text : mods_text + "+";
if (key->is_command_or_control_autoremap()) {
#ifdef MACOS_ENABLED
text = text.replace("Command", "Command/Ctrl");
mods_text = mods_text.replace("Command", "Command/Ctrl");
#else
text = text.replace("Ctrl", "Command/Ctrl");
mods_text = mods_text.replace("Ctrl", "Command/Ctrl");
#endif
}
if (key->get_keycode() != Key::NONE) {
text += mods_text + keycode_get_string(key->get_keycode());
}
if (key->get_physical_keycode() != Key::NONE) {
if (!text.is_empty()) {
text += " or ";
}
text += mods_text + keycode_get_string(key->get_physical_keycode()) + " (" + RTR("Physical") + ")";
}
if (key->get_key_label() != Key::NONE) {
if (!text.is_empty()) {
text += " or ";
}
text += mods_text + keycode_get_string(key->get_key_label()) + " (Unicode)";
}
if (text.is_empty()) {
text = "(" + RTR("Unset") + ")";
}
} else {
text = p_event->as_text();
}
Ref<InputEventMouse> mouse = p_event;
Ref<InputEventJoypadMotion> jp_motion = p_event;
Ref<InputEventJoypadButton> jp_button = p_event;

View File

@ -1 +1 @@
<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill-opacity=".996"><path d="m4 2a1 1 0 0 0 -1 1v9.084c0 .506.448.916 1 .916h8c.552 0 1-.41 1-.916v-9.084a1 1 0 0 0 -1-1zm1.543 1.139h1.393l1.834 4.199h1.295v.437c.708.052 1.246.239 1.61.559.368.316.55.747.55 1.295 0 .552-.182.99-.55 1.314-.368.32-.906.505-1.61.553v.467h-1.294v-.473c-.708-.06-1.247-.248-1.615-.564-.364-.316-.545-.75-.545-1.297 0-.548.181-.977.545-1.29.368-.315.907-.504 1.615-.564v-.437h-1.464l-.282-.733h-1.595l-.284.733h-1.439l1.836-4.2zm.684 1.39-.409 1.057h.817zm3.84 4.338v1.526c.28-.04.483-.12.607-.24.124-.125.185-.302.185-.53 0-.224-.063-.396-.191-.516-.124-.12-.326-.2-.602-.24zm-1.296.006c-.284.04-.487.12-.61.24-.12.116-.182.288-.182.516 0 .22.065.392.193.512.132.12.331.202.6.246v-1.514z" fill="#e0e0e0"/><path d="m27 2h7v14h-7z" fill="#fff"/><path d="m1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-9h-1v9a1 1 0 0 1 -1 1h-10a1 1 0 0 1 -1-1v-9z" fill="#e0e0e0"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16"><path d="M6.584 5.135 6.17 4.059l-.412 1.076h.826zm3.203 2.976a1.032 1.032 0 0 0-.287.041.953.953 0 0 0-.09.034c-.028.012-.057.024-.084.039a.912.912 0 0 0-.152.107.988.988 0 0 0-.23.305.937.937 0 0 0-.04.097 1.017 1.017 0 0 0-.068.323 1.553 1.553 0 0 0 0 .244 1.374 1.374 0 0 0 .068.328 1.03 1.03 0 0 0 .201.336c.023.022.045.044.069.064a.96.96 0 0 0 .152.104c.027.015.056.027.084.039.03.012.06.024.09.033a.965.965 0 0 0 .19.035 1.028 1.028 0 0 0 .197 0 .974.974 0 0 0 .36-.107.876.876 0 0 0 .077-.049.872.872 0 0 0 .074-.055.882.882 0 0 0 .13-.136.978.978 0 0 0 .177-.368 1.225 1.225 0 0 0 .035-.224 1.61 1.61 0 0 0 0-.244 1.361 1.361 0 0 0-.035-.223 1.092 1.092 0 0 0-.121-.285.87.87 0 0 0-.12-.15.862.862 0 0 0-.14-.124c-.025-.017-.05-.035-.078-.05-.027-.015-.056-.027-.086-.04a.892.892 0 0 0-.373-.074z" style="fill-opacity:.99607843;fill:#e0e0e0"/><path d="M4 2c-.616-.02-1.084.59-1 1.178.003 3-.007 6 .005 9 .057.577.672.889 1.203.822 2.631-.003 5.263.006 7.894-.005a.973.973 0 0 0 .898-1.09c-.003-3.002.007-6.005-.005-9.007-.042-.592-.643-.976-1.203-.898H4Zm1.475.646H6.89l1.865 4.27H7.268l-.286-.744H5.36l-.287.744H3.61l1.866-4.27Zm4.312 4.301c1.069-.042 2.164.679 2.363 1.766.232 1.01-.34 2.144-1.326 2.502.296.465.837-.109 1.06-.007l.544.642c-.64.756-1.883.677-2.605.084-.394-.448-.866-.673-1.409-.887-1.175-.66-1.391-2.456-.43-3.39.463-.486 1.141-.716 1.803-.71Z" style="fill:#e0e0e0;fill-opacity:.996078"/><path fill="#e0e0e0" d="M1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-1v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4Z" style="fill-opacity:.996"/></svg>

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16"><path d="M4 2c-.616-.02-1.084.59-1 1.178.003 3-.007 6 .005 9 .057.577.672.889 1.203.822 2.631-.003 5.263.006 7.894-.005a.973.973 0 0 0 .898-1.09c-.003-3.002.007-6.005-.005-9.007-.042-.592-.643-.976-1.203-.898H4Zm4.223 1.262c1.06.005 2.29.257 2.92 1.197.532.862.275 2.057-.484 2.703-.346.382-.862.629-1.075 1.117.055.345-.33.172-.537.213H7.148c-.037-.749.503-1.335 1.026-1.796.406-.253.744-1.002.129-1.22-.626-.25-1.374.117-1.645.715l-2.08-1.039c.599-1.147 1.868-1.818 3.136-1.872.17-.013.339-.018.509-.018Zm.127 5.697c.798-.057 1.616.616 1.54 1.45-.023.81-.841 1.413-1.623 1.328-.833.022-1.6-.771-1.443-1.613.097-.721.83-1.195 1.526-1.165z" style="fill:#ff5f5f;fill-opacity:1"/><path fill="#e0e0e0" d="M1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-1v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4Z" style="fill-opacity:1;fill:#ff5f5f"/></svg>

After

Width:  |  Height:  |  Size: 909 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M11.814 1.977c-.078 0-.157.008-.232.023H4c-.7-.034-1.143.765-1 1.39.008 2.95-.017 5.9.014 8.848.13.705.965.847 1.562.76 2.542-.008 5.085.02 7.627-.014.734-.1.9-.952.797-1.564-.003-2.84.006-5.68-.006-8.522-.035-.594-.628-.927-1.18-.921zM9.797 4.016l.572.58-.572.578-.57-.578.57-.58zm-.606 1.05.594.606-.594.601-.591-.601.591-.606zm1.213 0 .596.606-.596.601-.593-.601.593-.606zm.717 1.436h1.06c.053.217.093.428.122.63.028.201.043.395.043.58a2.363 2.363 0 0 1-.133.724 1.425 1.425 0 0 1-.31.515c-.249.265-.598.399-1.05.399-.331 0-.594-.08-.785-.235a1.091 1.091 0 0 1-.236-.275c-.063.1-.14.19-.236.265-.206.163-.467.245-.787.245-.252 0-.457-.057-.614-.166a2.75 2.75 0 0 1-.095.42 1.936 1.936 0 0 1-.403.722c-.2.22-.452.383-.756.49-.303.11-.654.166-1.052.166-.466 0-.865-.089-1.2-.265a1.817 1.817 0 0 1-.765-.752c-.18-.327-.27-.715-.27-1.164 0-.256.027-.525.082-.809.055-.284.126-.545.21-.781h1.001c-.062.232-.112.46-.15.684a3.87 3.87 0 0 0-.053.613c0 .37.1.643.3.82.204.177.523.264.96.264.222 0 .425-.03.61-.092a.97.97 0 0 0 .439-.299.803.803 0 0 0 .166-.521 5.463 5.463 0 0 0-.051-.725 11.61 11.61 0 0 0-.068-.482 26.51 26.51 0 0 0-.096-.606h1.135l.043.276c.047.32.123.532.228.634.105.1.24.15.402.15.165 0 .284-.04.358-.124.076-.086.115-.224.115-.412v-.524h1.027v.524c0 .203.032.351.096.447.065.095.202.142.412.142a.637.637 0 0 0 .33-.078c.089-.052.133-.15.133-.297 0-.128-.019-.295-.054-.498l-.108-.605z" style="fill:#e0e0e0;fill-opacity:.996078"/><path fill="#e0e0e0" d="M1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-1v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4Z" style="fill-opacity:.996"/></svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1 +1 @@
<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill-opacity=".996"><path d="m4 2a1 1 0 0 0 -1 1v9.084c0 .506.448.916 1 .916h8c.552 0 1-.41 1-.916v-9.084a1 1 0 0 0 -1-1zm2.762 1.768h2.476l3.264 7.464h-2.604l-.502-1.3h-2.835l-.502 1.3h-2.561zm1.217 2.474-.725 1.878h1.45z" fill="#e0e0e0"/><path d="m27 2h7v14h-7z" fill="#fff"/><path d="m1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-9h-1v9a1 1 0 0 1 -1 1h-10a1 1 0 0 1 -1-1v-9z" fill="#e0e0e0"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#e0e0e0" d="M4 2a1 1 0 0 0-1 1v9.084c0 .506.448.916 1 .916h8c.552 0 1-.41 1-.916V3a1 1 0 0 0-1-1Zm2.762 1.768h2.476l3.264 7.464H9.898l-.502-1.3H6.561l-.502 1.3H3.498Zm1.217 2.474L7.254 8.12h1.45z" style="fill-opacity:.996"/><path fill="#e0e0e0" d="M1 4v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-1v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4Z" style="fill-opacity:.996"/></svg>

Before

Width:  |  Height:  |  Size: 465 B

After

Width:  |  Height:  |  Size: 436 B

View File

@ -38,9 +38,10 @@
#include "scene/gui/separator.h"
#include "scene/gui/tree.h"
void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, bool p_update_input_list_selection) {
void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection) {
if (p_event.is_valid()) {
event = p_event;
original_event = p_original_event;
// If the event is changed to something which is not the same as the listener,
// clear out the event from the listener text box to avoid confusion.
@ -61,7 +62,7 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
// Update option values and visibility
bool show_mods = false;
bool show_device = false;
bool show_phys_key = false;
bool show_key = false;
if (mod.is_valid()) {
show_mods = true;
@ -74,9 +75,25 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
}
if (k.is_valid()) {
show_phys_key = true;
physical_key_checkbox->set_pressed(k->get_physical_keycode() != Key::NONE && k->get_keycode() == Key::NONE);
show_key = true;
if (k->get_keycode() == Key::NONE && k->get_physical_keycode() == Key::NONE && k->get_key_label() != Key::NONE) {
key_mode->select(KEYMODE_UNICODE);
} else if (k->get_keycode() != Key::NONE) {
key_mode->select(KEYMODE_KEYCODE);
} else if (k->get_physical_keycode() != Key::NONE) {
key_mode->select(KEYMODE_PHY_KEYCODE);
} else {
// Invalid key.
event = Ref<InputEvent>();
original_event = Ref<InputEvent>();
event_listener->clear_event();
event_as_text->set_text(TTR("No Event Configured"));
additional_options_container->hide();
input_list_tree->deselect_all();
_update_input_list();
return;
}
} else if (joyb.is_valid() || joym.is_valid() || mb.is_valid()) {
show_device = true;
_set_current_device(event->get_device());
@ -84,11 +101,20 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
mod_container->set_visible(show_mods);
device_container->set_visible(show_device);
physical_key_checkbox->set_visible(show_phys_key);
key_mode->set_visible(show_key);
additional_options_container->show();
// Update mode selector based on original key event.
Ref<InputEventKey> ko = p_original_event;
if (ko.is_valid()) {
key_mode->set_item_disabled(KEYMODE_KEYCODE, ko->get_keycode() == Key::NONE);
key_mode->set_item_disabled(KEYMODE_PHY_KEYCODE, ko->get_physical_keycode() == Key::NONE);
key_mode->set_item_disabled(KEYMODE_UNICODE, ko->get_key_label() == Key::NONE);
}
// Update selected item in input list.
if (p_update_input_list_selection && (k.is_valid() || joyb.is_valid() || joym.is_valid() || mb.is_valid())) {
in_tree_update = true;
TreeItem *category = input_list_tree->get_root()->get_first_child();
while (category) {
TreeItem *input_item = category->get_first_child();
@ -97,6 +123,7 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
// input_type should always be > 0, unless the tree structure has been misconfigured.
int input_type = input_item->get_parent()->get_meta("__type", 0);
if (input_type == 0) {
in_tree_update = false;
return;
}
@ -112,6 +139,7 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
category->set_collapsed(false);
input_item->select(0);
input_list_tree->ensure_cursor_is_visible();
in_tree_update = false;
return;
}
input_item = input_item->get_next();
@ -122,10 +150,12 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, b
category->set_collapsed(true); // Event not in this category, so collapse;
category = category->get_next();
}
in_tree_update = false;
}
} else {
// Event is not valid, reset dialog
event = p_event;
event = Ref<InputEvent>();
original_event = Ref<InputEvent>();
event_listener->clear_event();
event_as_text->set_text(TTR("No Event Configured"));
@ -141,8 +171,10 @@ void InputEventConfigurationDialog::_on_listen_input_changed(const Ref<InputEven
return;
}
// Create an editable reference
// Create an editable reference and a copy of full event.
Ref<InputEvent> received_event = p_event;
Ref<InputEvent> received_original_event = received_event->duplicate();
// Check what the type is and if it is allowed.
Ref<InputEventKey> k = received_event;
Ref<InputEventJoypadButton> joyb = received_event;
@ -169,12 +201,16 @@ void InputEventConfigurationDialog::_on_listen_input_changed(const Ref<InputEven
}
if (k.is_valid()) {
k->set_pressed(false); // To avoid serialization of 'pressed' property - doesn't matter for actions anyway.
// Maintain physical keycode option state
if (physical_key_checkbox->is_pressed()) {
k->set_keycode(Key::NONE);
} else {
k->set_pressed(false); // To avoid serialisation of 'pressed' property - doesn't matter for actions anyway.
if (key_mode->get_selected_id() == KEYMODE_KEYCODE) {
k->set_physical_keycode(Key::NONE);
k->set_key_label(Key::NONE);
} else if (key_mode->get_selected_id() == KEYMODE_PHY_KEYCODE) {
k->set_keycode(Key::NONE);
k->set_key_label(Key::NONE);
} else if (key_mode->get_selected_id() == KEYMODE_UNICODE) {
k->set_physical_keycode(Key::NONE);
k->set_keycode(Key::NONE);
}
}
@ -186,7 +222,7 @@ void InputEventConfigurationDialog::_on_listen_input_changed(const Ref<InputEven
// Maintain device selection.
received_event->set_device(_get_current_device());
_set_event(received_event);
_set_event(received_event, received_original_event);
}
void InputEventConfigurationDialog::_on_listen_focus_changed() {
@ -326,14 +362,14 @@ void InputEventConfigurationDialog::_mod_toggled(bool p_checked, int p_index) {
}
}
_set_event(ie);
_set_event(ie, original_event);
}
void InputEventConfigurationDialog::_autoremap_command_or_control_toggled(bool p_checked) {
Ref<InputEventWithModifiers> ie = event;
if (ie.is_valid()) {
ie->set_command_or_control_autoremap(p_checked);
_set_event(ie);
_set_event(ie, original_event);
}
if (p_checked) {
@ -345,27 +381,38 @@ void InputEventConfigurationDialog::_autoremap_command_or_control_toggled(bool p
}
}
void InputEventConfigurationDialog::_physical_keycode_toggled(bool p_checked) {
void InputEventConfigurationDialog::_key_mode_selected(int p_mode) {
Ref<InputEventKey> k = event;
if (k.is_null()) {
Ref<InputEventKey> ko = original_event;
if (k.is_null() || ko.is_null()) {
return;
}
if (p_checked) {
k->set_physical_keycode(k->get_keycode());
k->set_keycode(Key::NONE);
} else {
k->set_keycode((Key)k->get_physical_keycode());
if (key_mode->get_selected_id() == KEYMODE_KEYCODE) {
k->set_keycode(ko->get_keycode());
k->set_physical_keycode(Key::NONE);
k->set_key_label(Key::NONE);
} else if (key_mode->get_selected_id() == KEYMODE_PHY_KEYCODE) {
k->set_keycode(Key::NONE);
k->set_physical_keycode(ko->get_physical_keycode());
k->set_key_label(Key::NONE);
} else if (key_mode->get_selected_id() == KEYMODE_UNICODE) {
k->set_physical_keycode(Key::NONE);
k->set_keycode(Key::NONE);
k->set_key_label(ko->get_key_label());
}
_set_event(k);
_set_event(k, original_event);
}
void InputEventConfigurationDialog::_input_list_item_selected() {
TreeItem *selected = input_list_tree->get_selected();
// Called form _set_event, do not update for a second time.
if (in_tree_update) {
return;
}
// Invalid tree selection - type only exists on the "category" items, which are not a valid selection.
if (selected->has_meta("__type")) {
return;
@ -379,15 +426,11 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
Ref<InputEventKey> k;
k.instantiate();
if (physical_key_checkbox->is_pressed()) {
k->set_physical_keycode(keycode);
k->set_keycode(Key::NONE);
} else {
k->set_physical_keycode(Key::NONE);
k->set_keycode(keycode);
}
k->set_key_label(keycode);
// Maintain modifier state from checkboxes
// Maintain modifier state from checkboxes.
k->set_alt_pressed(mod_checkboxes[MOD_ALT]->is_pressed());
k->set_shift_pressed(mod_checkboxes[MOD_SHIFT]->is_pressed());
if (autoremap_command_or_control_checkbox->is_pressed()) {
@ -397,7 +440,23 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
k->set_meta_pressed(mod_checkboxes[MOD_META]->is_pressed());
}
_set_event(k, false);
Ref<InputEventKey> ko = k->duplicate();
if (key_mode->get_selected_id() == KEYMODE_UNICODE) {
key_mode->select(KEYMODE_PHY_KEYCODE);
}
if (key_mode->get_selected_id() == KEYMODE_KEYCODE) {
k->set_physical_keycode(Key::NONE);
k->set_keycode(keycode);
k->set_key_label(Key::NONE);
} else if (key_mode->get_selected_id() == KEYMODE_PHY_KEYCODE) {
k->set_physical_keycode(keycode);
k->set_keycode(Key::NONE);
k->set_key_label(Key::NONE);
}
_set_event(k, ko, false);
} break;
case INPUT_MOUSE_BUTTON: {
MouseButton idx = (MouseButton)(int)selected->get_meta("__index");
@ -417,7 +476,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
// Maintain selected device
mb->set_device(_get_current_device());
_set_event(mb, false);
_set_event(mb, mb, false);
} break;
case INPUT_JOY_BUTTON: {
JoyButton idx = (JoyButton)(int)selected->get_meta("__index");
@ -426,7 +485,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
// Maintain selected device
jb->set_device(_get_current_device());
_set_event(jb, false);
_set_event(jb, jb, false);
} break;
case INPUT_JOY_MOTION: {
JoyAxis axis = (JoyAxis)(int)selected->get_meta("__axis");
@ -440,7 +499,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
// Maintain selected device
jm->set_device(_get_current_device());
_set_event(jm, false);
_set_event(jm, jm, false);
} break;
}
}
@ -470,7 +529,9 @@ void InputEventConfigurationDialog::_notification(int p_what) {
case NOTIFICATION_THEME_CHANGED: {
input_list_search->set_right_icon(input_list_search->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
physical_key_checkbox->set_icon(get_theme_icon(SNAME("KeyboardPhysical"), SNAME("EditorIcons")));
key_mode->set_item_icon(KEYMODE_KEYCODE, get_theme_icon(SNAME("Keyboard"), SNAME("EditorIcons")));
key_mode->set_item_icon(KEYMODE_PHY_KEYCODE, get_theme_icon(SNAME("KeyboardPhysical"), SNAME("EditorIcons")));
key_mode->set_item_icon(KEYMODE_UNICODE, get_theme_icon(SNAME("KeyboardLabel"), SNAME("EditorIcons")));
icon_cache.keyboard = get_theme_icon(SNAME("Keyboard"), SNAME("EditorIcons"));
icon_cache.mouse = get_theme_icon(SNAME("Mouse"), SNAME("EditorIcons"));
@ -484,22 +545,22 @@ void InputEventConfigurationDialog::_notification(int p_what) {
void InputEventConfigurationDialog::popup_and_configure(const Ref<InputEvent> &p_event) {
if (p_event.is_valid()) {
_set_event(p_event);
_set_event(p_event, p_event->duplicate());
} else {
// Clear Event
_set_event(p_event);
_set_event(Ref<InputEvent>(), Ref<InputEvent>());
// Clear Checkbox Values
for (int i = 0; i < MOD_MAX; i++) {
mod_checkboxes[i]->set_pressed(false);
}
// Enable the Physical Key checkbox by default to encourage its use.
// Enable the Physical Key by default to encourage its use.
// Physical Key should be used for most game inputs as it allows keys to work
// on non-QWERTY layouts out of the box.
// This is especially important for WASD movement layouts.
physical_key_checkbox->set_pressed(true);
key_mode->select(KEYMODE_PHY_KEYCODE);
autoremap_command_or_control_checkbox->set_pressed(false);
// Select "All Devices" by default.
@ -621,14 +682,15 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() {
mod_container->hide();
additional_options_container->add_child(mod_container);
// Physical Key Checkbox
// Key Mode Selection
physical_key_checkbox = memnew(CheckBox);
physical_key_checkbox->set_text(TTR("Use Physical Keycode"));
physical_key_checkbox->set_tooltip_text(TTR("Stores the physical position of the key on the keyboard rather than the key's value. Used for compatibility with non-latin layouts.\nThis should generally be enabled for most game shortcuts, but not in non-game applications."));
physical_key_checkbox->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_physical_keycode_toggled));
physical_key_checkbox->hide();
additional_options_container->add_child(physical_key_checkbox);
key_mode = memnew(OptionButton);
key_mode->add_item("Keycode (Latin equvialent)", KEYMODE_KEYCODE);
key_mode->add_item("Physical Keycode (poistion of US QWERTY keyboard)", KEYMODE_PHY_KEYCODE);
key_mode->add_item("Unicode (case-insencetive)", KEYMODE_UNICODE);
key_mode->connect("item_selected", callable_mp(this, &InputEventConfigurationDialog::_key_mode_selected));
key_mode->hide();
additional_options_container->add_child(key_mode);
main_vbox->add_child(additional_options_container);
}

View File

@ -50,7 +50,10 @@ private:
Ref<Texture2D> joypad_axis;
} icon_cache;
Ref<InputEvent> event = Ref<InputEvent>();
Ref<InputEvent> event;
Ref<InputEvent> original_event;
bool in_tree_update = false;
// Listening for input
EventListenerLineEdit *event_listener = nullptr;
@ -88,9 +91,15 @@ private:
CheckBox *mod_checkboxes[MOD_MAX];
CheckBox *autoremap_command_or_control_checkbox = nullptr;
CheckBox *physical_key_checkbox = nullptr;
enum KeyMode {
KEYMODE_KEYCODE,
KEYMODE_PHY_KEYCODE,
KEYMODE_UNICODE,
};
void _set_event(const Ref<InputEvent> &p_event, bool p_update_input_list_selection = true);
OptionButton *key_mode = nullptr;
void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true);
void _on_listen_input_changed(const Ref<InputEvent> &p_event);
void _on_listen_focus_changed();
@ -100,7 +109,7 @@ private:
void _mod_toggled(bool p_checked, int p_index);
void _autoremap_command_or_control_toggled(bool p_checked);
void _physical_keycode_toggled(bool p_checked);
void _key_mode_selected(int p_mode);
void _device_selection_changed(int p_option_button_index);
void _set_current_device(int p_device);

View File

@ -56,7 +56,7 @@ void AndroidInputHandler::_set_key_modifier_state(Ref<InputEventWithModifiers> e
ev->set_ctrl_pressed(control_mem);
}
void AndroidInputHandler::process_key_event(int p_keycode, int p_physical_keycode, int p_unicode, bool p_pressed) {
void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed) {
static char32_t prev_wc = 0;
char32_t unicode = p_unicode;
if ((p_unicode & 0xfffffc00) == 0xd800) {
@ -80,10 +80,7 @@ void AndroidInputHandler::process_key_event(int p_keycode, int p_physical_keycod
ev.instantiate();
Key physical_keycode = godot_code_from_android_code(p_physical_keycode);
Key keycode = physical_keycode;
if (p_keycode != 0) {
keycode = godot_code_from_unicode(p_keycode);
}
Key keycode = fix_keycode(unicode, physical_keycode);
switch (physical_keycode) {
case Key::SHIFT: {
@ -104,7 +101,8 @@ void AndroidInputHandler::process_key_event(int p_keycode, int p_physical_keycod
ev->set_keycode(keycode);
ev->set_physical_keycode(physical_keycode);
ev->set_unicode(unicode);
ev->set_key_label(fix_key_label(p_key_label, keycode));
ev->set_unicode(fix_unicode(unicode));
ev->set_pressed(p_pressed);
_set_key_modifier_state(ev);

View File

@ -97,7 +97,7 @@ public:
void process_magnify(Point2 p_pos, float p_factor);
void process_pan(Point2 p_pos, Vector2 p_delta);
void process_joy_event(JoypadEvent p_event);
void process_key_event(int p_keycode, int p_physical_keycode, int p_unicode, bool p_pressed);
void process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed);
};
#endif // ANDROID_INPUT_HANDLER_H

View File

@ -38,41 +38,3 @@ Key godot_code_from_android_code(unsigned int p_code) {
}
return Key::UNKNOWN;
}
Key godot_code_from_unicode(unsigned int p_code) {
unsigned int code = p_code;
if (code > 0xFF) {
return Key::UNKNOWN;
}
// Known control codes.
if (code == '\b') { // 0x08
return Key::BACKSPACE;
}
if (code == '\t') { // 0x09
return Key::TAB;
}
if (code == '\n') { // 0x0A
return Key::ENTER;
}
if (code == 0x1B) {
return Key::ESCAPE;
}
if (code == 0x1F) {
return Key::KEY_DELETE;
}
// Unknown control codes.
if (code <= 0x1F || (code >= 0x80 && code <= 0x9F)) {
return Key::UNKNOWN;
}
// Convert to uppercase.
if (code >= 'a' && code <= 'z') { // 0x61 - 0x7A
code -= ('a' - 'A');
}
if (code >= u'à' && code <= u'ö') { // 0xE0 - 0xF6
code -= (u'à' - u'À'); // 0xE0 - 0xC0
}
if (code >= u'ø' && code <= u'þ') { // 0xF8 - 0xFF
code -= (u'ø' - u'Ø'); // 0xF8 - 0xD8
}
return Key(code);
}

View File

@ -165,13 +165,14 @@ static AndroidGodotCodePair android_godot_code_pairs[] = {
{ AKEYCODE_NUMPAD_DOT, Key::KP_PERIOD }, // (158) Numeric keypad '.' key (for decimals or digit grouping).
{ AKEYCODE_NUMPAD_ENTER, Key::KP_ENTER }, // (160) Numeric keypad Enter key.
{ AKEYCODE_VOLUME_MUTE, Key::VOLUMEMUTE }, // (164) Volume Mute key.
{ AKEYCODE_EISU, Key::JIS_EISU }, // (212) JIS EISU key.
{ AKEYCODE_YEN, Key::YEN }, // (216) Japanese Yen key.
{ AKEYCODE_KANA, Key::JIS_KANA }, // (218) JIS KANA key.
{ AKEYCODE_HELP, Key::HELP }, // (259) Help key.
{ AKEYCODE_REFRESH, Key::REFRESH }, // (285) Refresh key.
{ AKEYCODE_MAX, Key::UNKNOWN }
};
Key godot_code_from_android_code(unsigned int p_code);
Key godot_code_from_unicode(unsigned int p_code);
#endif // ANDROID_KEYS_UTILS_H

View File

@ -148,7 +148,7 @@ public class GodotLib {
/**
* Forward regular key events.
*/
public static native void key(int p_keycode, int p_physical_keycode, int p_unicode, boolean p_pressed);
public static native void key(int p_physical_keycode, int p_unicode, int p_key_label, boolean p_pressed);
/**
* Forward game device's key events.

View File

@ -129,12 +129,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
}
} else {
// getKeyCode(): The physical key that was pressed.
// Godot's keycodes match the ASCII codes, so for single byte unicode characters,
// we can use the unmodified unicode character to determine Godot's keycode.
final int keycode = event.getUnicodeChar(0);
final int physical_keycode = event.getKeyCode();
final int unicode = event.getUnicodeChar();
GodotLib.key(keycode, physical_keycode, unicode, false);
final int key_label = event.getDisplayLabel();
GodotLib.key(physical_keycode, unicode, key_label, false);
};
return true;
@ -166,10 +164,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
GodotLib.joybutton(godotJoyId, button, true);
}
} else {
final int keycode = event.getUnicodeChar(0);
final int physical_keycode = event.getKeyCode();
final int unicode = event.getUnicodeChar();
GodotLib.key(keycode, physical_keycode, unicode, true);
final int key_label = event.getDisplayLabel();
GodotLib.key(physical_keycode, unicode, key_label, true);
}
return true;

View File

@ -93,8 +93,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
for (int i = 0; i < count; ++i) {
GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, true);
GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, false);
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, true);
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, false);
if (mHasSelection) {
mHasSelection = false;
@ -110,13 +110,13 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
newChars[i - start] = pCharSequence.charAt(i);
}
for (int i = 0; i < count; ++i) {
int key = newChars[i];
if ((key == '\n') && !(mEdit.getKeyboardType() == GodotEditText.VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE)) {
final int character = newChars[i];
if ((character == '\n') && !(mEdit.getKeyboardType() == GodotEditText.VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE)) {
// Return keys are handled through action events
continue;
}
GodotLib.key(key, 0, key, true);
GodotLib.key(key, 0, key, false);
GodotLib.key(0, character, 0, true);
GodotLib.key(0, character, 0, false);
}
}
@ -126,17 +126,17 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
final String characters = pKeyEvent.getCharacters();
for (int i = 0; i < characters.length(); i++) {
final int ch = characters.codePointAt(i);
GodotLib.key(ch, 0, ch, true);
GodotLib.key(ch, 0, ch, false);
final int character = characters.codePointAt(i);
GodotLib.key(0, character, 0, true);
GodotLib.key(0, character, 0, false);
}
}
if (pActionID == EditorInfo.IME_ACTION_DONE) {
// Enter key has been pressed
mRenderView.queueOnRenderThread(() -> {
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, true);
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, false);
GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, true);
GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, false);
});
mRenderView.getView().requestFocus();
return true;

View File

@ -382,11 +382,11 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
}
// Called on the UI thread
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_physical_keycode, jint p_unicode, jboolean p_pressed) {
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed) {
if (step.get() <= 0) {
return;
}
input_handler->process_key_event(p_keycode, p_physical_keycode, p_unicode, p_pressed);
input_handler->process_key_event(p_physical_keycode, p_unicode, p_key_label, p_pressed);
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {

View File

@ -49,7 +49,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JN
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jboolean p_double_tap);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_pan(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_physical_keycode, jint p_unicode, jboolean p_pressed);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y);

View File

@ -20,6 +20,7 @@ ios_lib = [
"godot_view_gesture_recognizer.mm",
"device_metrics.m",
"keyboard_input_view.mm",
"key_mapping_ios.mm",
]
env_ios = env.Clone()

View File

@ -117,7 +117,8 @@ public:
// MARK: Keyboard
void key(Key p_key, char32_t p_char, bool p_pressed);
void key(Key p_key, char32_t p_char, Key p_unshifted, Key p_physical, NSInteger p_modifier, bool p_pressed);
bool is_keyboard_active() const;
// MARK: Motion

View File

@ -36,6 +36,7 @@
#import "device_metrics.h"
#import "godot_view.h"
#include "ios.h"
#import "key_mapping_ios.h"
#import "keyboard_input_view.h"
#include "os_ios.h"
#include "tts_ios.h"
@ -50,6 +51,8 @@ DisplayServerIOS *DisplayServerIOS::get_singleton() {
}
DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
KeyMappingIOS::initialize();
rendering_driver = p_rendering_driver;
// Init TTS
@ -231,14 +234,29 @@ void DisplayServerIOS::touches_canceled(int p_idx) {
// MARK: Keyboard
void DisplayServerIOS::key(Key p_key, char32_t p_char, bool p_pressed) {
void DisplayServerIOS::key(Key p_key, char32_t p_char, Key p_unshifted, Key p_physical, NSInteger p_modifier, bool p_pressed) {
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_echo(false);
ev->set_pressed(p_pressed);
ev->set_keycode(p_key);
ev->set_physical_keycode(p_key);
ev->set_unicode(p_char);
ev->set_keycode(fix_keycode(p_char, p_key));
if (@available(iOS 13.4, *)) {
if (p_key != Key::SHIFT) {
ev->set_shift_pressed(p_modifier & UIKeyModifierShift);
}
if (p_key != Key::CTRL) {
ev->set_ctrl_pressed(p_modifier & UIKeyModifierControl);
}
if (p_key != Key::ALT) {
ev->set_alt_pressed(p_modifier & UIKeyModifierAlternate);
}
if (p_key != Key::META) {
ev->set_meta_pressed(p_modifier & UIKeyModifierCommand);
}
}
ev->set_key_label(p_unshifted);
ev->set_physical_keycode(p_physical);
ev->set_unicode(fix_unicode(p_char));
perform_event(ev);
}
@ -616,6 +634,10 @@ void DisplayServerIOS::virtual_keyboard_show(const String &p_existing_text, cons
cursorEnd:_convert_utf32_offset_to_utf16(p_existing_text, p_cursor_end)];
}
bool DisplayServerIOS::is_keyboard_active() const {
return [AppDelegate.viewController.keyboardView isFirstResponder];
}
void DisplayServerIOS::virtual_keyboard_hide() {
[AppDelegate.viewController.keyboardView resignFirstResponder];
}

View File

@ -0,0 +1,46 @@
/**************************************************************************/
/* key_mapping_ios.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef KEY_MAPPING_IOS_H
#define KEY_MAPPING_IOS_H
#include "core/os/keyboard.h"
#import <UIKit/UIKit.h>
class KeyMappingIOS {
KeyMappingIOS() {}
public:
static void initialize();
static Key remap_key(CFIndex p_keycode);
};
#endif // KEY_MAPPING_IOS_H

View File

@ -0,0 +1,186 @@
/**************************************************************************/
/* key_mapping_ios.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "key_mapping_ios.h"
#include "core/templates/hash_map.h"
struct HashMapHasherKeys {
static _FORCE_INLINE_ uint32_t hash(const Key p_key) { return hash_fmix32(static_cast<uint32_t>(p_key)); }
static _FORCE_INLINE_ uint32_t hash(const CFIndex p_key) { return hash_fmix32(p_key); }
};
HashMap<CFIndex, Key, HashMapHasherKeys> keyusage_map;
void KeyMappingIOS::initialize() {
if (@available(iOS 13.4, *)) {
keyusage_map[UIKeyboardHIDUsageKeyboardA] = Key::A;
keyusage_map[UIKeyboardHIDUsageKeyboardB] = Key::B;
keyusage_map[UIKeyboardHIDUsageKeyboardC] = Key::C;
keyusage_map[UIKeyboardHIDUsageKeyboardD] = Key::D;
keyusage_map[UIKeyboardHIDUsageKeyboardE] = Key::E;
keyusage_map[UIKeyboardHIDUsageKeyboardF] = Key::F;
keyusage_map[UIKeyboardHIDUsageKeyboardG] = Key::G;
keyusage_map[UIKeyboardHIDUsageKeyboardH] = Key::H;
keyusage_map[UIKeyboardHIDUsageKeyboardI] = Key::I;
keyusage_map[UIKeyboardHIDUsageKeyboardJ] = Key::J;
keyusage_map[UIKeyboardHIDUsageKeyboardK] = Key::K;
keyusage_map[UIKeyboardHIDUsageKeyboardL] = Key::L;
keyusage_map[UIKeyboardHIDUsageKeyboardM] = Key::M;
keyusage_map[UIKeyboardHIDUsageKeyboardN] = Key::N;
keyusage_map[UIKeyboardHIDUsageKeyboardO] = Key::O;
keyusage_map[UIKeyboardHIDUsageKeyboardP] = Key::P;
keyusage_map[UIKeyboardHIDUsageKeyboardQ] = Key::Q;
keyusage_map[UIKeyboardHIDUsageKeyboardR] = Key::R;
keyusage_map[UIKeyboardHIDUsageKeyboardS] = Key::S;
keyusage_map[UIKeyboardHIDUsageKeyboardT] = Key::T;
keyusage_map[UIKeyboardHIDUsageKeyboardU] = Key::U;
keyusage_map[UIKeyboardHIDUsageKeyboardV] = Key::V;
keyusage_map[UIKeyboardHIDUsageKeyboardW] = Key::W;
keyusage_map[UIKeyboardHIDUsageKeyboardX] = Key::X;
keyusage_map[UIKeyboardHIDUsageKeyboardY] = Key::Y;
keyusage_map[UIKeyboardHIDUsageKeyboardZ] = Key::Z;
keyusage_map[UIKeyboardHIDUsageKeyboard0] = Key::KEY_0;
keyusage_map[UIKeyboardHIDUsageKeyboard1] = Key::KEY_1;
keyusage_map[UIKeyboardHIDUsageKeyboard2] = Key::KEY_2;
keyusage_map[UIKeyboardHIDUsageKeyboard3] = Key::KEY_3;
keyusage_map[UIKeyboardHIDUsageKeyboard4] = Key::KEY_4;
keyusage_map[UIKeyboardHIDUsageKeyboard5] = Key::KEY_5;
keyusage_map[UIKeyboardHIDUsageKeyboard6] = Key::KEY_6;
keyusage_map[UIKeyboardHIDUsageKeyboard7] = Key::KEY_7;
keyusage_map[UIKeyboardHIDUsageKeyboard8] = Key::KEY_8;
keyusage_map[UIKeyboardHIDUsageKeyboard9] = Key::KEY_9;
keyusage_map[UIKeyboardHIDUsageKeyboardBackslash] = Key::BACKSLASH;
keyusage_map[UIKeyboardHIDUsageKeyboardCloseBracket] = Key::BRACKETRIGHT;
keyusage_map[UIKeyboardHIDUsageKeyboardComma] = Key::COMMA;
keyusage_map[UIKeyboardHIDUsageKeyboardEqualSign] = Key::EQUAL;
keyusage_map[UIKeyboardHIDUsageKeyboardHyphen] = Key::MINUS;
keyusage_map[UIKeyboardHIDUsageKeyboardNonUSBackslash] = Key::SECTION;
keyusage_map[UIKeyboardHIDUsageKeyboardNonUSPound] = Key::ASCIITILDE;
keyusage_map[UIKeyboardHIDUsageKeyboardOpenBracket] = Key::BRACKETLEFT;
keyusage_map[UIKeyboardHIDUsageKeyboardPeriod] = Key::PERIOD;
keyusage_map[UIKeyboardHIDUsageKeyboardQuote] = Key::QUOTEDBL;
keyusage_map[UIKeyboardHIDUsageKeyboardSemicolon] = Key::SEMICOLON;
keyusage_map[UIKeyboardHIDUsageKeyboardSeparator] = Key::SECTION;
keyusage_map[UIKeyboardHIDUsageKeyboardSlash] = Key::SLASH;
keyusage_map[UIKeyboardHIDUsageKeyboardSpacebar] = Key::SPACE;
keyusage_map[UIKeyboardHIDUsageKeyboardCapsLock] = Key::CAPSLOCK;
keyusage_map[UIKeyboardHIDUsageKeyboardLeftAlt] = Key::ALT;
keyusage_map[UIKeyboardHIDUsageKeyboardLeftControl] = Key::CTRL;
keyusage_map[UIKeyboardHIDUsageKeyboardLeftShift] = Key::SHIFT;
keyusage_map[UIKeyboardHIDUsageKeyboardRightAlt] = Key::ALT;
keyusage_map[UIKeyboardHIDUsageKeyboardRightControl] = Key::CTRL;
keyusage_map[UIKeyboardHIDUsageKeyboardRightShift] = Key::SHIFT;
keyusage_map[UIKeyboardHIDUsageKeyboardScrollLock] = Key::SCROLLLOCK;
keyusage_map[UIKeyboardHIDUsageKeyboardLeftArrow] = Key::LEFT;
keyusage_map[UIKeyboardHIDUsageKeyboardRightArrow] = Key::RIGHT;
keyusage_map[UIKeyboardHIDUsageKeyboardUpArrow] = Key::UP;
keyusage_map[UIKeyboardHIDUsageKeyboardDownArrow] = Key::DOWN;
keyusage_map[UIKeyboardHIDUsageKeyboardPageUp] = Key::PAGEUP;
keyusage_map[UIKeyboardHIDUsageKeyboardPageDown] = Key::PAGEDOWN;
keyusage_map[UIKeyboardHIDUsageKeyboardHome] = Key::HOME;
keyusage_map[UIKeyboardHIDUsageKeyboardEnd] = Key::END;
keyusage_map[UIKeyboardHIDUsageKeyboardDeleteForward] = Key::KEY_DELETE;
keyusage_map[UIKeyboardHIDUsageKeyboardDeleteOrBackspace] = Key::BACKSPACE;
keyusage_map[UIKeyboardHIDUsageKeyboardEscape] = Key::ESCAPE;
keyusage_map[UIKeyboardHIDUsageKeyboardInsert] = Key::INSERT;
keyusage_map[UIKeyboardHIDUsageKeyboardReturn] = Key::ENTER;
keyusage_map[UIKeyboardHIDUsageKeyboardTab] = Key::TAB;
keyusage_map[UIKeyboardHIDUsageKeyboardF1] = Key::F1;
keyusage_map[UIKeyboardHIDUsageKeyboardF2] = Key::F2;
keyusage_map[UIKeyboardHIDUsageKeyboardF3] = Key::F3;
keyusage_map[UIKeyboardHIDUsageKeyboardF4] = Key::F4;
keyusage_map[UIKeyboardHIDUsageKeyboardF5] = Key::F5;
keyusage_map[UIKeyboardHIDUsageKeyboardF6] = Key::F6;
keyusage_map[UIKeyboardHIDUsageKeyboardF7] = Key::F7;
keyusage_map[UIKeyboardHIDUsageKeyboardF8] = Key::F8;
keyusage_map[UIKeyboardHIDUsageKeyboardF9] = Key::F9;
keyusage_map[UIKeyboardHIDUsageKeyboardF10] = Key::F10;
keyusage_map[UIKeyboardHIDUsageKeyboardF11] = Key::F11;
keyusage_map[UIKeyboardHIDUsageKeyboardF12] = Key::F12;
keyusage_map[UIKeyboardHIDUsageKeyboardF13] = Key::F13;
keyusage_map[UIKeyboardHIDUsageKeyboardF14] = Key::F14;
keyusage_map[UIKeyboardHIDUsageKeyboardF15] = Key::F15;
keyusage_map[UIKeyboardHIDUsageKeyboardF16] = Key::F16;
keyusage_map[UIKeyboardHIDUsageKeyboardF17] = Key::F17;
keyusage_map[UIKeyboardHIDUsageKeyboardF18] = Key::F18;
keyusage_map[UIKeyboardHIDUsageKeyboardF19] = Key::F19;
keyusage_map[UIKeyboardHIDUsageKeyboardF20] = Key::F20;
keyusage_map[UIKeyboardHIDUsageKeyboardF21] = Key::F21;
keyusage_map[UIKeyboardHIDUsageKeyboardF22] = Key::F22;
keyusage_map[UIKeyboardHIDUsageKeyboardF23] = Key::F23;
keyusage_map[UIKeyboardHIDUsageKeyboardF24] = Key::F24;
keyusage_map[UIKeyboardHIDUsageKeypad0] = Key::KP_0;
keyusage_map[UIKeyboardHIDUsageKeypad1] = Key::KP_1;
keyusage_map[UIKeyboardHIDUsageKeypad2] = Key::KP_2;
keyusage_map[UIKeyboardHIDUsageKeypad3] = Key::KP_3;
keyusage_map[UIKeyboardHIDUsageKeypad4] = Key::KP_4;
keyusage_map[UIKeyboardHIDUsageKeypad5] = Key::KP_5;
keyusage_map[UIKeyboardHIDUsageKeypad6] = Key::KP_6;
keyusage_map[UIKeyboardHIDUsageKeypad7] = Key::KP_7;
keyusage_map[UIKeyboardHIDUsageKeypad8] = Key::KP_8;
keyusage_map[UIKeyboardHIDUsageKeypad9] = Key::KP_9;
keyusage_map[UIKeyboardHIDUsageKeypadAsterisk] = Key::KP_MULTIPLY;
keyusage_map[UIKeyboardHIDUsageKeyboardGraveAccentAndTilde] = Key::BAR;
keyusage_map[UIKeyboardHIDUsageKeypadEnter] = Key::KP_ENTER;
keyusage_map[UIKeyboardHIDUsageKeypadHyphen] = Key::KP_SUBTRACT;
keyusage_map[UIKeyboardHIDUsageKeypadNumLock] = Key::NUMLOCK;
keyusage_map[UIKeyboardHIDUsageKeypadPeriod] = Key::KP_PERIOD;
keyusage_map[UIKeyboardHIDUsageKeypadPlus] = Key::KP_ADD;
keyusage_map[UIKeyboardHIDUsageKeypadSlash] = Key::KP_DIVIDE;
keyusage_map[UIKeyboardHIDUsageKeyboardPause] = Key::PAUSE;
keyusage_map[UIKeyboardHIDUsageKeyboardStop] = Key::STOP;
keyusage_map[UIKeyboardHIDUsageKeyboardMute] = Key::VOLUMEMUTE;
keyusage_map[UIKeyboardHIDUsageKeyboardVolumeUp] = Key::VOLUMEUP;
keyusage_map[UIKeyboardHIDUsageKeyboardVolumeDown] = Key::VOLUMEDOWN;
keyusage_map[UIKeyboardHIDUsageKeyboardFind] = Key::SEARCH;
keyusage_map[UIKeyboardHIDUsageKeyboardHelp] = Key::HELP;
keyusage_map[UIKeyboardHIDUsageKeyboardLeftGUI] = Key::META;
keyusage_map[UIKeyboardHIDUsageKeyboardRightGUI] = Key::META;
keyusage_map[UIKeyboardHIDUsageKeyboardMenu] = Key::MENU;
keyusage_map[UIKeyboardHIDUsageKeyboardPrintScreen] = Key::PRINT;
keyusage_map[UIKeyboardHIDUsageKeyboardReturnOrEnter] = Key::ENTER;
keyusage_map[UIKeyboardHIDUsageKeyboardSysReqOrAttention] = Key::SYSREQ;
keyusage_map[0x01AE] = Key::KEYBOARD; // On-screen keyboard key on smart connector keyboard.
keyusage_map[0x029D] = Key::GLOBE; // "Globe" key on smart connector / Mac keyboard.
keyusage_map[UIKeyboardHIDUsageKeyboardLANG1] = Key::JIS_EISU;
keyusage_map[UIKeyboardHIDUsageKeyboardLANG2] = Key::JIS_KANA;
}
}
Key KeyMappingIOS::remap_key(CFIndex p_keycode) {
if (@available(iOS 13.4, *)) {
const Key *key = keyusage_map.getptr(p_keycode);
if (key) {
return *key;
}
}
return Key::NONE;
}

View File

@ -115,8 +115,8 @@
- (void)deleteText:(NSInteger)charactersToDelete {
for (int i = 0; i < charactersToDelete; i++) {
DisplayServerIOS::get_singleton()->key(Key::BACKSPACE, 0, true);
DisplayServerIOS::get_singleton()->key(Key::BACKSPACE, 0, false);
DisplayServerIOS::get_singleton()->key(Key::BACKSPACE, 0, Key::BACKSPACE, Key::NONE, 0, true);
DisplayServerIOS::get_singleton()->key(Key::BACKSPACE, 0, Key::BACKSPACE, Key::NONE, 0, false);
}
}
@ -134,20 +134,10 @@
key = Key::ENTER;
} else if (character == 0x2006) {
key = Key::SPACE;
} else if (character == U'¥') {
key = Key::YEN;
} else if (character == U'§') {
key = Key::SECTION;
} else if (character >= 0x20 && character <= 0x7E) { // ASCII.
if (character > 0x60 && character < 0x7B) { // Lowercase ASCII.
key = (Key)(character - 32);
} else {
key = (Key)character;
}
}
DisplayServerIOS::get_singleton()->key(key, character, true);
DisplayServerIOS::get_singleton()->key(key, character, false);
DisplayServerIOS::get_singleton()->key(key, character, key, Key::NONE, 0, true);
DisplayServerIOS::get_singleton()->key(key, character, key, Key::NONE, 0, false);
}
}

View File

@ -33,6 +33,7 @@
#include "display_server_ios.h"
#import "godot_view.h"
#import "godot_view_renderer.h"
#import "key_mapping_ios.h"
#import "keyboard_input_view.h"
#include "os_ios.h"
@ -54,6 +55,64 @@
return (GodotView *)self.view;
}
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
[super pressesBegan:presses withEvent:event];
if (!DisplayServerIOS::get_singleton() || DisplayServerIOS::get_singleton()->is_keyboard_active()) {
return;
}
if (@available(iOS 13.4, *)) {
for (UIPress *press in presses) {
String u32lbl = String::utf8([press.key.charactersIgnoringModifiers UTF8String]);
String u32text = String::utf8([press.key.characters UTF8String]);
Key key = KeyMappingIOS::remap_key(press.key.keyCode);
if (press.key.keyCode == 0 && u32text.is_empty() && u32lbl.is_empty()) {
continue;
}
char32_t us = 0;
if (!u32lbl.is_empty() && !u32lbl.begins_with("UIKey")) {
us = u32lbl[0];
}
if (!u32text.is_empty() && !u32text.begins_with("UIKey")) {
for (int i = 0; i < u32text.length(); i++) {
const char32_t c = u32text[i];
DisplayServerIOS::get_singleton()->key(fix_keycode(us, key), c, fix_key_label(us, key), key, press.key.modifierFlags, true);
}
} else {
DisplayServerIOS::get_singleton()->key(fix_keycode(us, key), 0, fix_key_label(us, key), key, press.key.modifierFlags, true);
}
}
}
}
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
[super pressesEnded:presses withEvent:event];
if (!DisplayServerIOS::get_singleton() || DisplayServerIOS::get_singleton()->is_keyboard_active()) {
return;
}
if (@available(iOS 13.4, *)) {
for (UIPress *press in presses) {
String u32lbl = String::utf8([press.key.charactersIgnoringModifiers UTF8String]);
Key key = KeyMappingIOS::remap_key(press.key.keyCode);
if (press.key.keyCode == 0 && u32lbl.is_empty()) {
continue;
}
char32_t us = 0;
if (!u32lbl.is_empty() && !u32lbl.begins_with("UIKey")) {
us = u32lbl[0];
}
DisplayServerIOS::get_singleton()->key(fix_keycode(us, key), 0, fix_key_label(us, key), key, press.key.modifierFlags, false);
}
}
}
- (void)loadView {
GodotView *view = [[GodotView alloc] init];
GodotViewRenderer *renderer = [[GodotViewRenderer alloc] init];

View File

@ -192,6 +192,7 @@ def configure(env: "Environment"):
env.ParseConfig("pkg-config xrandr --cflags")
env.ParseConfig("pkg-config xrender --cflags")
env.ParseConfig("pkg-config xi --cflags")
env.ParseConfig("pkg-config xkbcommon --cflags")
if env["touch"]:
env.Append(CPPDEFINES=["TOUCH_ENABLED"])

View File

@ -9,6 +9,7 @@ source_files = [
"dynwrappers/xcursor-so_wrap.c",
"dynwrappers/xinerama-so_wrap.c",
"dynwrappers/xinput2-so_wrap.c",
"dynwrappers/xkbcommon-so_wrap.c",
"dynwrappers/xrandr-so_wrap.c",
"dynwrappers/xrender-so_wrap.c",
"dynwrappers/xext-so_wrap.c",

View File

@ -1324,6 +1324,8 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) {
}
#endif
XDestroyWindow(x11_display, wd.x11_xim_window);
XUnmapWindow(x11_display, wd.x11_window);
XDestroyWindow(x11_display, wd.x11_window);
if (wd.xic) {
@ -2490,24 +2492,39 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
wd.im_active = p_active;
if (!wd.xic) {
return;
}
if (!wd.focused) {
return;
}
// Block events polling while changing input focus
// because it triggers some event polling internally.
if (p_active) {
{
MutexLock mutex_lock(events_mutex);
XSetICFocus(wd.xic);
wd.ime_active = true;
XMapWindow(x11_display, wd.x11_xim_window);
XWindowAttributes xwa;
XSync(x11_display, False);
XGetWindowAttributes(x11_display, wd.x11_xim_window, &xwa);
if (xwa.map_state == IsViewable) {
XSetInputFocus(x11_display, wd.x11_xim_window, RevertToPointerRoot, CurrentTime);
}
window_set_ime_position(wd.im_position, p_window);
XSetICFocus(wd.xic);
} else {
MutexLock mutex_lock(events_mutex);
XUnsetICFocus(wd.xic);
XUnmapWindow(x11_display, wd.x11_xim_window);
wd.ime_active = false;
im_text = String();
im_selection = Vector2i();
}
OS_Unix::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
void DisplayServerX11::window_set_ime_position(const Point2i &p_pos, WindowID p_window) {
@ -2516,25 +2533,29 @@ void DisplayServerX11::window_set_ime_position(const Point2i &p_pos, WindowID p_
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
wd.im_position = p_pos;
if (!wd.xic) {
return;
}
::XPoint spot;
spot.x = short(p_pos.x);
spot.y = short(p_pos.y);
XVaNestedList preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, nullptr);
{
// Block events polling during this call
// because it triggers some event polling internally.
MutexLock mutex_lock(events_mutex);
XSetICValues(wd.xic, XNPreeditAttributes, preedit_attr, nullptr);
if (!wd.focused) {
return;
}
XFree(preedit_attr);
if (wd.ime_active) {
XWindowAttributes xwa;
XSync(x11_display, False);
XGetWindowAttributes(x11_display, wd.x11_xim_window, &xwa);
if (xwa.map_state == IsViewable) {
XMoveWindow(x11_display, wd.x11_xim_window, p_pos.x, p_pos.y);
}
}
}
Point2i DisplayServerX11::ime_get_selection() const {
return im_selection;
}
String DisplayServerX11::ime_get_text() const {
return im_text;
}
void DisplayServerX11::cursor_set_shape(CursorShape p_shape) {
@ -2872,6 +2893,16 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
// X11 functions don't know what const is
XKeyEvent *xkeyevent = p_event;
if (wd.ime_in_progress) {
return;
}
if (wd.ime_suppress_next_keyup) {
wd.ime_suppress_next_keyup = false;
if (xkeyevent->type != KeyPress) {
return;
}
}
// This code was pretty difficult to write.
// The docs stink and every toolkit seems to
// do it in a different way.
@ -2895,12 +2926,18 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
KeySym keysym_unicode = 0; // keysym used to find unicode
// XLookupString returns keysyms usable as nice keycodes.
char str[256 + 1];
char str[256] = {};
XKeyEvent xkeyevent_no_mod = *xkeyevent;
xkeyevent_no_mod.state &= ~ShiftMask;
xkeyevent_no_mod.state &= ~ControlMask;
XLookupString(xkeyevent, str, 256, &keysym_unicode, nullptr);
XLookupString(&xkeyevent_no_mod, nullptr, 0, &keysym_keycode, nullptr);
XLookupString(xkeyevent, str, 255, &keysym_unicode, nullptr);
String keysym;
if (xkb_keysym_to_utf32 && xkb_keysym_to_upper) {
KeySym keysym_unicode_nm = 0; // keysym used to find unicode
XLookupString(&xkeyevent_no_mod, nullptr, 0, &keysym_unicode_nm, nullptr);
keysym = String::chr(xkb_keysym_to_utf32(xkb_keysym_to_upper(keysym_unicode_nm)));
}
// Meanwhile, XLookupString returns keysyms useful for unicode.
@ -2950,13 +2987,18 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
_get_key_modifier_state(xkeyevent->state, k);
k->set_window_id(p_window);
k->set_unicode(tmp[i]);
k->set_pressed(keypress);
k->set_keycode(keycode);
k->set_physical_keycode((Key)physical_keycode);
k->set_physical_keycode(physical_keycode);
if (!keysym.is_empty()) {
k->set_key_label(fix_key_label(keysym[0], keycode));
} else {
k->set_key_label(keycode);
}
if (keypress) {
k->set_unicode(fix_unicode(tmp[i]));
}
k->set_echo(false);
@ -2999,7 +3041,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
// KeyMappingX11 also translates keysym to unicode.
// It does a binary search on a table to translate
// most properly.
unsigned int unicode = keysym_unicode > 0 ? KeyMappingX11::get_unicode_from_keysym(keysym_unicode) : 0;
char32_t unicode = keysym_unicode > 0 ? KeyMappingX11::get_unicode_from_keysym(keysym_unicode) : 0;
/* Phase 4, determine if event must be filtered */
@ -3085,7 +3127,14 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
k->set_keycode(keycode);
k->set_physical_keycode((Key)physical_keycode);
k->set_unicode(unicode);
if (!keysym.is_empty()) {
k->set_key_label(fix_key_label(keysym[0], keycode));
} else {
k->set_key_label(keycode);
}
if (keypress) {
k->set_unicode(fix_unicode(unicode));
}
k->set_echo(p_echo);
if (k->get_keycode() == Key::BACKTAB) {
@ -3237,6 +3286,80 @@ void DisplayServerX11::_handle_selection_request_event(XSelectionRequestEvent *p
XFlush(x11_display);
}
int DisplayServerX11::_xim_preedit_start_callback(::XIM xim, ::XPointer client_data,
::XPointer call_data) {
DisplayServerX11 *ds = reinterpret_cast<DisplayServerX11 *>(client_data);
WindowID window_id = ds->_get_focused_window_or_popup();
WindowData &wd = ds->windows[window_id];
if (wd.ime_active) {
wd.ime_in_progress = true;
}
return -1; // Allow preedit strings of any length (no limit).
}
void DisplayServerX11::_xim_preedit_done_callback(::XIM xim, ::XPointer client_data,
::XPointer call_data) {
DisplayServerX11 *ds = reinterpret_cast<DisplayServerX11 *>(client_data);
WindowID window_id = ds->_get_focused_window_or_popup();
WindowData &wd = ds->windows[window_id];
if (wd.ime_active) {
wd.ime_in_progress = false;
wd.ime_suppress_next_keyup = true;
}
}
void DisplayServerX11::_xim_preedit_draw_callback(::XIM xim, ::XPointer client_data,
::XIMPreeditDrawCallbackStruct *call_data) {
DisplayServerX11 *ds = reinterpret_cast<DisplayServerX11 *>(client_data);
WindowID window_id = ds->_get_focused_window_or_popup();
WindowData &wd = ds->windows[window_id];
XIMText *xim_text = call_data->text;
if (xim_text != nullptr) {
String changed_text;
if (xim_text->encoding_is_wchar) {
changed_text = String(xim_text->string.wide_char);
} else {
changed_text.parse_utf8(xim_text->string.multi_byte);
}
if (call_data->chg_length < 0) {
ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text;
} else {
ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text + ds->im_text.substr(call_data->chg_length);
}
// Find the start and end of the selection.
int start = 0, count = 0;
for (int i = 0; i < xim_text->length; i++) {
if (xim_text->feedback[i] & XIMReverse) {
if (count == 0) {
start = i;
count = 1;
} else {
count++;
}
}
}
if (count > 0) {
ds->im_selection = Point2i(start + call_data->chg_first, count);
} else {
ds->im_selection = Point2i(call_data->caret, 0);
}
} else {
ds->im_text = String();
ds->im_selection = Point2i();
}
if (wd.ime_active) {
OS_Unix::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
}
void DisplayServerX11::_xim_preedit_caret_callback(::XIM xim, ::XPointer client_data,
::XIMPreeditCaretCallbackStruct *call_data) {
}
void DisplayServerX11::_xim_destroy_callback(::XIM im, ::XPointer client_data,
::XPointer call_data) {
WARN_PRINT("Input method stopped");
@ -3286,10 +3409,6 @@ void DisplayServerX11::_window_changed(XEvent *event) {
if (new_rect == Rect2i(wd.position, wd.size)) {
return;
}
if (wd.xic) {
// Not portable.
window_set_ime_position(Point2(0, 1));
}
wd.position = new_rect.position;
wd.size = new_rect.size;
@ -3637,6 +3756,7 @@ void DisplayServerX11::process_events() {
continue;
}
bool ime_window_event = false;
WindowID window_id = MAIN_WINDOW_ID;
// Assign the event to the relevant window
@ -3645,6 +3765,11 @@ void DisplayServerX11::process_events() {
window_id = E.key;
break;
}
if (event.xany.window == E.value.x11_xim_window) {
window_id = E.key;
ime_window_event = true;
break;
}
}
if (XGetEventData(x11_display, &event.xcookie)) {
@ -3659,6 +3784,9 @@ void DisplayServerX11::process_events() {
_refresh_device_info();
} break;
case XI_RawMotion: {
if (ime_window_event) {
break;
}
XIRawEvent *raw_event = (XIRawEvent *)event_data;
int device_id = raw_event->sourceid;
@ -3761,6 +3889,9 @@ void DisplayServerX11::process_events() {
#ifdef TOUCH_ENABLED
case XI_TouchBegin:
case XI_TouchEnd: {
if (ime_window_event) {
break;
}
bool is_begin = event_data->evtype == XI_TouchBegin;
Ref<InputEventScreenTouch> st;
@ -3791,6 +3922,9 @@ void DisplayServerX11::process_events() {
} break;
case XI_TouchUpdate: {
if (ime_window_event) {
break;
}
HashMap<int, Vector2>::Iterator curr_pos_elem = xi.state.find(index);
if (!curr_pos_elem) { // Defensive
break;
@ -3817,6 +3951,9 @@ void DisplayServerX11::process_events() {
switch (event.type) {
case MapNotify: {
DEBUG_LOG_X11("[%u] MapNotify window=%lu (%u) \n", frame, event.xmap.window, window_id);
if (ime_window_event) {
break;
}
const WindowData &wd = windows[window_id];
@ -3837,6 +3974,9 @@ void DisplayServerX11::process_events() {
case Expose: {
DEBUG_LOG_X11("[%u] Expose window=%lu (%u), count='%u' \n", frame, event.xexpose.window, window_id, event.xexpose.count);
if (ime_window_event) {
break;
}
windows[window_id].fullscreen = _window_fullscreen_check(window_id);
@ -3845,18 +3985,27 @@ void DisplayServerX11::process_events() {
case NoExpose: {
DEBUG_LOG_X11("[%u] NoExpose drawable=%lu (%u) \n", frame, event.xnoexpose.drawable, window_id);
if (ime_window_event) {
break;
}
windows[window_id].minimized = true;
} break;
case VisibilityNotify: {
DEBUG_LOG_X11("[%u] VisibilityNotify window=%lu (%u), state=%u \n", frame, event.xvisibility.window, window_id, event.xvisibility.state);
if (ime_window_event) {
break;
}
windows[window_id].minimized = _window_minimize_check(window_id);
} break;
case LeaveNotify: {
DEBUG_LOG_X11("[%u] LeaveNotify window=%lu (%u), mode='%u' \n", frame, event.xcrossing.window, window_id, event.xcrossing.mode);
if (ime_window_event) {
break;
}
if (!mouse_mode_grab) {
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT);
@ -3866,6 +4015,9 @@ void DisplayServerX11::process_events() {
case EnterNotify: {
DEBUG_LOG_X11("[%u] EnterNotify window=%lu (%u), mode='%u' \n", frame, event.xcrossing.window, window_id, event.xcrossing.mode);
if (ime_window_event) {
break;
}
if (!mouse_mode_grab) {
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
@ -3874,18 +4026,14 @@ void DisplayServerX11::process_events() {
case FocusIn: {
DEBUG_LOG_X11("[%u] FocusIn window=%lu (%u), mode='%u' \n", frame, event.xfocus.window, window_id, event.xfocus.mode);
if (ime_window_event) {
break;
}
WindowData &wd = windows[window_id];
last_focused_window = window_id;
wd.focused = true;
if (wd.xic) {
// Block events polling while changing input focus
// because it triggers some event polling internally.
MutexLock mutex_lock(events_mutex);
XSetICFocus(wd.xic);
}
// Keep track of focus order for overlapping windows.
static unsigned int focus_order = 0;
wd.focus_order = ++focus_order;
@ -3925,17 +4073,20 @@ void DisplayServerX11::process_events() {
case FocusOut: {
DEBUG_LOG_X11("[%u] FocusOut window=%lu (%u), mode='%u' \n", frame, event.xfocus.window, window_id, event.xfocus.mode);
WindowData &wd = windows[window_id];
wd.focused = false;
if (wd.xic) {
// Block events polling while changing input focus
// because it triggers some event polling internally.
if (wd.ime_active && event.xfocus.detail == NotifyInferior) {
break;
}
if (wd.ime_active) {
MutexLock mutex_lock(events_mutex);
XUnsetICFocus(wd.xic);
XUnmapWindow(x11_display, wd.x11_xim_window);
wd.ime_active = false;
im_text = String();
im_selection = Vector2i();
OS_Unix::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
wd.focused = false;
Input::get_singleton()->release_pressed_events();
_send_window_event(wd, WINDOW_EVENT_FOCUS_OUT);
@ -3971,6 +4122,9 @@ void DisplayServerX11::process_events() {
case ConfigureNotify: {
DEBUG_LOG_X11("[%u] ConfigureNotify window=%lu (%u), event=%lu, above=%lu, override_redirect=%u \n", frame, event.xconfigure.window, window_id, event.xconfigure.event, event.xconfigure.above, event.xconfigure.override_redirect);
if (event.xconfigure.window == windows[window_id].x11_xim_window) {
break;
}
const WindowData &wd = windows[window_id];
@ -3990,6 +4144,9 @@ void DisplayServerX11::process_events() {
case ButtonPress:
case ButtonRelease: {
if (ime_window_event) {
break;
}
/* exit in case of a mouse button press */
last_timestamp = event.xbutton.time;
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@ -4088,6 +4245,9 @@ void DisplayServerX11::process_events() {
} break;
case MotionNotify: {
if (ime_window_event) {
break;
}
// The X11 API requires filtering one-by-one through the motion
// notify events, in order to figure out which event is the one
// generated by warping the mouse pointer.
@ -4248,7 +4408,9 @@ void DisplayServerX11::process_events() {
} break;
case SelectionNotify:
if (ime_window_event) {
break;
}
if (event.xselection.target == requested) {
Property p = _read_property(x11_display, windows[window_id].x11_window, XInternAtom(x11_display, "PRIMARY", 0));
@ -4283,7 +4445,9 @@ void DisplayServerX11::process_events() {
break;
case ClientMessage:
if (ime_window_event) {
break;
}
if ((unsigned int)event.xclient.data.l[0] == (unsigned int)wm_delete) {
_send_window_event(windows[window_id], WINDOW_EVENT_CLOSE_REQUEST);
}
@ -4692,6 +4856,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
{
wd.x11_window = XCreateWindow(x11_display, RootWindow(x11_display, visualInfo.screen), win_rect.position.x, win_rect.position.y, win_rect.size.width > 0 ? win_rect.size.width : 1, win_rect.size.height > 0 ? win_rect.size.height : 1, 0, visualInfo.depth, InputOutput, visualInfo.visual, valuemask, &windowAttributes);
wd.x11_xim_window = XCreateWindow(x11_display, wd.x11_window, 0, 0, 1, 1, 0, visualInfo.depth, InputOutput, visualInfo.visual, valuemask, &windowAttributes);
// Enable receiving notification when the window is initialized (MapNotify)
// so the focus can be set at the right time.
@ -4763,7 +4928,50 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
// because it triggers some event polling internally.
MutexLock mutex_lock(events_mutex);
wd.xic = XCreateIC(xim, XNInputStyle, xim_style, XNClientWindow, wd.x11_window, XNFocusWindow, wd.x11_window, (char *)nullptr);
// Force on-the-spot for the over-the-spot style.
if ((xim_style & XIMPreeditPosition) != 0) {
xim_style &= ~XIMPreeditPosition;
xim_style |= XIMPreeditCallbacks;
}
if ((xim_style & XIMPreeditCallbacks) != 0) {
::XIMCallback preedit_start_callback;
preedit_start_callback.client_data = (::XPointer)(this);
preedit_start_callback.callback = (::XIMProc)(void *)(_xim_preedit_start_callback);
::XIMCallback preedit_done_callback;
preedit_done_callback.client_data = (::XPointer)(this);
preedit_done_callback.callback = (::XIMProc)(_xim_preedit_done_callback);
::XIMCallback preedit_draw_callback;
preedit_draw_callback.client_data = (::XPointer)(this);
preedit_draw_callback.callback = (::XIMProc)(_xim_preedit_draw_callback);
::XIMCallback preedit_caret_callback;
preedit_caret_callback.client_data = (::XPointer)(this);
preedit_caret_callback.callback = (::XIMProc)(_xim_preedit_caret_callback);
::XVaNestedList preedit_attributes = XVaCreateNestedList(0,
XNPreeditStartCallback, &preedit_start_callback,
XNPreeditDoneCallback, &preedit_done_callback,
XNPreeditDrawCallback, &preedit_draw_callback,
XNPreeditCaretCallback, &preedit_caret_callback,
(char *)nullptr);
wd.xic = XCreateIC(xim,
XNInputStyle, xim_style,
XNClientWindow, wd.x11_xim_window,
XNFocusWindow, wd.x11_xim_window,
XNPreeditAttributes, preedit_attributes,
(char *)nullptr);
XFree(preedit_attributes);
} else {
wd.xic = XCreateIC(xim,
XNInputStyle, xim_style,
XNClientWindow, wd.x11_xim_window,
XNFocusWindow, wd.x11_xim_window,
(char *)nullptr);
}
if (XGetICValues(wd.xic, XNFilterEvents, &im_event_mask, nullptr) != nullptr) {
WARN_PRINT("XGetICValues couldn't obtain XNFilterEvents value");
XDestroyIC(wd.xic);
@ -4854,7 +5062,66 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
return id;
}
static bool _is_xim_style_supported(const ::XIMStyle &p_style) {
const ::XIMStyle supported_preedit = XIMPreeditCallbacks | XIMPreeditPosition | XIMPreeditNothing | XIMPreeditNone;
const ::XIMStyle supported_status = XIMStatusNothing | XIMStatusNone;
// Check preedit style is supported
if ((p_style & supported_preedit) == 0) {
return false;
}
// Check status style is supported
if ((p_style & supported_status) == 0) {
return false;
}
return true;
}
static ::XIMStyle _get_best_xim_style(const ::XIMStyle &p_style_a, const ::XIMStyle &p_style_b) {
if (p_style_a == 0) {
return p_style_b;
}
if (p_style_b == 0) {
return p_style_a;
}
const ::XIMStyle preedit = XIMPreeditArea | XIMPreeditCallbacks | XIMPreeditPosition | XIMPreeditNothing | XIMPreeditNone;
const ::XIMStyle status = XIMStatusArea | XIMStatusCallbacks | XIMStatusNothing | XIMStatusNone;
::XIMStyle a = p_style_a & preedit;
::XIMStyle b = p_style_b & preedit;
if (a != b) {
// Compare preedit styles.
if ((a | b) & XIMPreeditCallbacks) {
return a == XIMPreeditCallbacks ? p_style_a : p_style_b;
} else if ((a | b) & XIMPreeditPosition) {
return a == XIMPreeditPosition ? p_style_a : p_style_b;
} else if ((a | b) & XIMPreeditArea) {
return a == XIMPreeditArea ? p_style_a : p_style_b;
} else if ((a | b) & XIMPreeditNothing) {
return a == XIMPreeditNothing ? p_style_a : p_style_b;
}
} else {
// Preedit styles are the same, compare status styles.
a = p_style_a & status;
b = p_style_b & status;
if ((a | b) & XIMStatusCallbacks) {
return a == XIMStatusCallbacks ? p_style_a : p_style_b;
} else if ((a | b) & XIMStatusArea) {
return a == XIMStatusArea ? p_style_a : p_style_b;
} else if ((a | b) & XIMStatusNothing) {
return a == XIMStatusNothing ? p_style_a : p_style_b;
}
}
return p_style_a;
}
DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
KeyMappingX11::initialize();
#ifdef DEBUG_ENABLED
int dylibloader_verbose = 1;
#else
@ -4870,6 +5137,8 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
ERR_FAIL_MSG("Can't load XCursor dynamically.");
}
initialize_xkbcommon(dylibloader_verbose); // Optional, used for key_label.
if (initialize_xext(dylibloader_verbose) != 0) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Can't load Xext dynamically.");
@ -5001,11 +5270,13 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
if (xim_styles) {
xim_style = 0L;
for (int i = 0; i < xim_styles->count_styles; i++) {
if (xim_styles->supported_styles[i] ==
(XIMPreeditNothing | XIMStatusNothing)) {
xim_style = xim_styles->supported_styles[i];
break;
const ::XIMStyle &style = xim_styles->supported_styles[i];
if (!_is_xim_style_supported(style)) {
continue;
}
xim_style = _get_best_xim_style(xim_style, style);
}
XFree(xim_styles);

View File

@ -75,6 +75,7 @@
#include "dynwrappers/xext-so_wrap.h"
#include "dynwrappers/xinerama-so_wrap.h"
#include "dynwrappers/xinput2-so_wrap.h"
#include "dynwrappers/xkbcommon-so_wrap.h"
#include "dynwrappers/xrandr-so_wrap.h"
#include "dynwrappers/xrender-so_wrap.h"
@ -135,14 +136,16 @@ class DisplayServerX11 : public DisplayServer {
struct WindowData {
Window x11_window;
Window x11_xim_window;
::XIC xic;
bool ime_active = false;
bool ime_in_progress = false;
bool ime_suppress_next_keyup = false;
Size2i min_size;
Size2i max_size;
Point2i position;
Size2i size;
Point2i im_position;
bool im_active = false;
Callable rect_changed_callback;
Callable event_callback;
Callable input_event_callback;
@ -178,6 +181,9 @@ class DisplayServerX11 : public DisplayServer {
unsigned int focus_order = 0;
};
Point2i im_selection;
String im_text;
HashMap<WindowID, WindowData> windows;
unsigned int last_mouse_monitor_mask = 0;
@ -200,6 +206,15 @@ class DisplayServerX11 : public DisplayServer {
::Time last_keyrelease_time = 0;
::XIM xim;
::XIMStyle xim_style;
static int _xim_preedit_start_callback(::XIM xim, ::XPointer client_data,
::XPointer call_data);
static void _xim_preedit_done_callback(::XIM xim, ::XPointer client_data,
::XPointer call_data);
static void _xim_preedit_draw_callback(::XIM xim, ::XPointer client_data,
::XIMPreeditDrawCallbackStruct *call_data);
static void _xim_preedit_caret_callback(::XIM xim, ::XPointer client_data,
::XIMPreeditCaretCallbackStruct *call_data);
static void _xim_destroy_callback(::XIM im, ::XPointer client_data,
::XPointer call_data);
@ -433,6 +448,9 @@ public:
virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID) override;
virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID) override;
virtual Point2i ime_get_selection() const override;
virtual String ime_get_text() const override;
virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;

View File

@ -0,0 +1,859 @@
// This file is generated. Do not edit!
// see https://github.com/hpvb/dynload-wrapper for details
// generated by ./generate-wrapper.py 0.3 on 2023-01-23 14:25:23
// flags: ./generate-wrapper.py --include /usr/include/xkbcommon/xkbcommon.h --sys-include <xkbcommon/xkbcommon.h> --soname libxkbcommon.so.0 --init-name xkbcommon --output-header xkbcommon-so_wrap.h --output-implementation xkbcommon-so_wrap.c
//
#include <stdint.h>
#define xkb_keysym_get_name xkb_keysym_get_name_dylibloader_orig_xkbcommon
#define xkb_keysym_from_name xkb_keysym_from_name_dylibloader_orig_xkbcommon
#define xkb_keysym_to_utf8 xkb_keysym_to_utf8_dylibloader_orig_xkbcommon
#define xkb_keysym_to_utf32 xkb_keysym_to_utf32_dylibloader_orig_xkbcommon
#define xkb_utf32_to_keysym xkb_utf32_to_keysym_dylibloader_orig_xkbcommon
#define xkb_keysym_to_upper xkb_keysym_to_upper_dylibloader_orig_xkbcommon
#define xkb_keysym_to_lower xkb_keysym_to_lower_dylibloader_orig_xkbcommon
#define xkb_context_new xkb_context_new_dylibloader_orig_xkbcommon
#define xkb_context_ref xkb_context_ref_dylibloader_orig_xkbcommon
#define xkb_context_unref xkb_context_unref_dylibloader_orig_xkbcommon
#define xkb_context_set_user_data xkb_context_set_user_data_dylibloader_orig_xkbcommon
#define xkb_context_get_user_data xkb_context_get_user_data_dylibloader_orig_xkbcommon
#define xkb_context_include_path_append xkb_context_include_path_append_dylibloader_orig_xkbcommon
#define xkb_context_include_path_append_default xkb_context_include_path_append_default_dylibloader_orig_xkbcommon
#define xkb_context_include_path_reset_defaults xkb_context_include_path_reset_defaults_dylibloader_orig_xkbcommon
#define xkb_context_include_path_clear xkb_context_include_path_clear_dylibloader_orig_xkbcommon
#define xkb_context_num_include_paths xkb_context_num_include_paths_dylibloader_orig_xkbcommon
#define xkb_context_include_path_get xkb_context_include_path_get_dylibloader_orig_xkbcommon
#define xkb_context_set_log_level xkb_context_set_log_level_dylibloader_orig_xkbcommon
#define xkb_context_get_log_level xkb_context_get_log_level_dylibloader_orig_xkbcommon
#define xkb_context_set_log_verbosity xkb_context_set_log_verbosity_dylibloader_orig_xkbcommon
#define xkb_context_get_log_verbosity xkb_context_get_log_verbosity_dylibloader_orig_xkbcommon
#define xkb_context_set_log_fn xkb_context_set_log_fn_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_names xkb_keymap_new_from_names_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_file xkb_keymap_new_from_file_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_string xkb_keymap_new_from_string_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_buffer xkb_keymap_new_from_buffer_dylibloader_orig_xkbcommon
#define xkb_keymap_ref xkb_keymap_ref_dylibloader_orig_xkbcommon
#define xkb_keymap_unref xkb_keymap_unref_dylibloader_orig_xkbcommon
#define xkb_keymap_get_as_string xkb_keymap_get_as_string_dylibloader_orig_xkbcommon
#define xkb_keymap_min_keycode xkb_keymap_min_keycode_dylibloader_orig_xkbcommon
#define xkb_keymap_max_keycode xkb_keymap_max_keycode_dylibloader_orig_xkbcommon
#define xkb_keymap_key_for_each xkb_keymap_key_for_each_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_name xkb_keymap_key_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_key_by_name xkb_keymap_key_by_name_dylibloader_orig_xkbcommon
#define xkb_keymap_num_mods xkb_keymap_num_mods_dylibloader_orig_xkbcommon
#define xkb_keymap_mod_get_name xkb_keymap_mod_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_mod_get_index xkb_keymap_mod_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_layouts xkb_keymap_num_layouts_dylibloader_orig_xkbcommon
#define xkb_keymap_layout_get_name xkb_keymap_layout_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_layout_get_index xkb_keymap_layout_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_leds xkb_keymap_num_leds_dylibloader_orig_xkbcommon
#define xkb_keymap_led_get_name xkb_keymap_led_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_led_get_index xkb_keymap_led_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_layouts_for_key xkb_keymap_num_layouts_for_key_dylibloader_orig_xkbcommon
#define xkb_keymap_num_levels_for_key xkb_keymap_num_levels_for_key_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_mods_for_level xkb_keymap_key_get_mods_for_level_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_syms_by_level xkb_keymap_key_get_syms_by_level_dylibloader_orig_xkbcommon
#define xkb_keymap_key_repeats xkb_keymap_key_repeats_dylibloader_orig_xkbcommon
#define xkb_state_new xkb_state_new_dylibloader_orig_xkbcommon
#define xkb_state_ref xkb_state_ref_dylibloader_orig_xkbcommon
#define xkb_state_unref xkb_state_unref_dylibloader_orig_xkbcommon
#define xkb_state_get_keymap xkb_state_get_keymap_dylibloader_orig_xkbcommon
#define xkb_state_update_key xkb_state_update_key_dylibloader_orig_xkbcommon
#define xkb_state_update_mask xkb_state_update_mask_dylibloader_orig_xkbcommon
#define xkb_state_key_get_syms xkb_state_key_get_syms_dylibloader_orig_xkbcommon
#define xkb_state_key_get_utf8 xkb_state_key_get_utf8_dylibloader_orig_xkbcommon
#define xkb_state_key_get_utf32 xkb_state_key_get_utf32_dylibloader_orig_xkbcommon
#define xkb_state_key_get_one_sym xkb_state_key_get_one_sym_dylibloader_orig_xkbcommon
#define xkb_state_key_get_layout xkb_state_key_get_layout_dylibloader_orig_xkbcommon
#define xkb_state_key_get_level xkb_state_key_get_level_dylibloader_orig_xkbcommon
#define xkb_state_serialize_mods xkb_state_serialize_mods_dylibloader_orig_xkbcommon
#define xkb_state_serialize_layout xkb_state_serialize_layout_dylibloader_orig_xkbcommon
#define xkb_state_mod_name_is_active xkb_state_mod_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_names_are_active xkb_state_mod_names_are_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_active xkb_state_mod_index_is_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_indices_are_active xkb_state_mod_indices_are_active_dylibloader_orig_xkbcommon
#define xkb_state_key_get_consumed_mods2 xkb_state_key_get_consumed_mods2_dylibloader_orig_xkbcommon
#define xkb_state_key_get_consumed_mods xkb_state_key_get_consumed_mods_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_consumed2 xkb_state_mod_index_is_consumed2_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_consumed xkb_state_mod_index_is_consumed_dylibloader_orig_xkbcommon
#define xkb_state_mod_mask_remove_consumed xkb_state_mod_mask_remove_consumed_dylibloader_orig_xkbcommon
#define xkb_state_layout_name_is_active xkb_state_layout_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_layout_index_is_active xkb_state_layout_index_is_active_dylibloader_orig_xkbcommon
#define xkb_state_led_name_is_active xkb_state_led_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_led_index_is_active xkb_state_led_index_is_active_dylibloader_orig_xkbcommon
#include <xkbcommon/xkbcommon.h>
#undef xkb_keysym_get_name
#undef xkb_keysym_from_name
#undef xkb_keysym_to_utf8
#undef xkb_keysym_to_utf32
#undef xkb_utf32_to_keysym
#undef xkb_keysym_to_upper
#undef xkb_keysym_to_lower
#undef xkb_context_new
#undef xkb_context_ref
#undef xkb_context_unref
#undef xkb_context_set_user_data
#undef xkb_context_get_user_data
#undef xkb_context_include_path_append
#undef xkb_context_include_path_append_default
#undef xkb_context_include_path_reset_defaults
#undef xkb_context_include_path_clear
#undef xkb_context_num_include_paths
#undef xkb_context_include_path_get
#undef xkb_context_set_log_level
#undef xkb_context_get_log_level
#undef xkb_context_set_log_verbosity
#undef xkb_context_get_log_verbosity
#undef xkb_context_set_log_fn
#undef xkb_keymap_new_from_names
#undef xkb_keymap_new_from_file
#undef xkb_keymap_new_from_string
#undef xkb_keymap_new_from_buffer
#undef xkb_keymap_ref
#undef xkb_keymap_unref
#undef xkb_keymap_get_as_string
#undef xkb_keymap_min_keycode
#undef xkb_keymap_max_keycode
#undef xkb_keymap_key_for_each
#undef xkb_keymap_key_get_name
#undef xkb_keymap_key_by_name
#undef xkb_keymap_num_mods
#undef xkb_keymap_mod_get_name
#undef xkb_keymap_mod_get_index
#undef xkb_keymap_num_layouts
#undef xkb_keymap_layout_get_name
#undef xkb_keymap_layout_get_index
#undef xkb_keymap_num_leds
#undef xkb_keymap_led_get_name
#undef xkb_keymap_led_get_index
#undef xkb_keymap_num_layouts_for_key
#undef xkb_keymap_num_levels_for_key
#undef xkb_keymap_key_get_mods_for_level
#undef xkb_keymap_key_get_syms_by_level
#undef xkb_keymap_key_repeats
#undef xkb_state_new
#undef xkb_state_ref
#undef xkb_state_unref
#undef xkb_state_get_keymap
#undef xkb_state_update_key
#undef xkb_state_update_mask
#undef xkb_state_key_get_syms
#undef xkb_state_key_get_utf8
#undef xkb_state_key_get_utf32
#undef xkb_state_key_get_one_sym
#undef xkb_state_key_get_layout
#undef xkb_state_key_get_level
#undef xkb_state_serialize_mods
#undef xkb_state_serialize_layout
#undef xkb_state_mod_name_is_active
#undef xkb_state_mod_names_are_active
#undef xkb_state_mod_index_is_active
#undef xkb_state_mod_indices_are_active
#undef xkb_state_key_get_consumed_mods2
#undef xkb_state_key_get_consumed_mods
#undef xkb_state_mod_index_is_consumed2
#undef xkb_state_mod_index_is_consumed
#undef xkb_state_mod_mask_remove_consumed
#undef xkb_state_layout_name_is_active
#undef xkb_state_layout_index_is_active
#undef xkb_state_led_name_is_active
#undef xkb_state_led_index_is_active
#include <dlfcn.h>
#include <stdio.h>
int (*xkb_keysym_get_name_dylibloader_wrapper_xkbcommon)( xkb_keysym_t, char*, size_t);
xkb_keysym_t (*xkb_keysym_from_name_dylibloader_wrapper_xkbcommon)(const char*,enum xkb_keysym_flags);
int (*xkb_keysym_to_utf8_dylibloader_wrapper_xkbcommon)( xkb_keysym_t, char*, size_t);
uint32_t (*xkb_keysym_to_utf32_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
xkb_keysym_t (*xkb_utf32_to_keysym_dylibloader_wrapper_xkbcommon)( uint32_t);
xkb_keysym_t (*xkb_keysym_to_upper_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
xkb_keysym_t (*xkb_keysym_to_lower_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
struct xkb_context* (*xkb_context_new_dylibloader_wrapper_xkbcommon)(enum xkb_context_flags);
struct xkb_context* (*xkb_context_ref_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
void (*xkb_context_unref_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
void (*xkb_context_set_user_data_dylibloader_wrapper_xkbcommon)(struct xkb_context*, void*);
void* (*xkb_context_get_user_data_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
int (*xkb_context_include_path_append_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*);
int (*xkb_context_include_path_append_default_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
int (*xkb_context_include_path_reset_defaults_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
void (*xkb_context_include_path_clear_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
unsigned int (*xkb_context_num_include_paths_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
const char* (*xkb_context_include_path_get_dylibloader_wrapper_xkbcommon)(struct xkb_context*, unsigned int);
void (*xkb_context_set_log_level_dylibloader_wrapper_xkbcommon)(struct xkb_context*,enum xkb_log_level);
enum xkb_log_level (*xkb_context_get_log_level_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
void (*xkb_context_set_log_verbosity_dylibloader_wrapper_xkbcommon)(struct xkb_context*, int);
int (*xkb_context_get_log_verbosity_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
void (*xkb_context_set_log_fn_dylibloader_wrapper_xkbcommon)(struct xkb_context*, void*);
struct xkb_keymap* (*xkb_keymap_new_from_names_dylibloader_wrapper_xkbcommon)(struct xkb_context*,struct xkb_rule_names*,enum xkb_keymap_compile_flags);
struct xkb_keymap* (*xkb_keymap_new_from_file_dylibloader_wrapper_xkbcommon)(struct xkb_context*, FILE*,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
struct xkb_keymap* (*xkb_keymap_new_from_string_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
struct xkb_keymap* (*xkb_keymap_new_from_buffer_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*, size_t,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
struct xkb_keymap* (*xkb_keymap_ref_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
void (*xkb_keymap_unref_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
char* (*xkb_keymap_get_as_string_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,enum xkb_keymap_format);
xkb_keycode_t (*xkb_keymap_min_keycode_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
xkb_keycode_t (*xkb_keymap_max_keycode_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
void (*xkb_keymap_key_for_each_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keymap_key_iter_t, void*);
const char* (*xkb_keymap_key_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
xkb_keycode_t (*xkb_keymap_key_by_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
xkb_mod_index_t (*xkb_keymap_num_mods_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
const char* (*xkb_keymap_mod_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_mod_index_t);
xkb_mod_index_t (*xkb_keymap_mod_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
xkb_layout_index_t (*xkb_keymap_num_layouts_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
const char* (*xkb_keymap_layout_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_layout_index_t);
xkb_layout_index_t (*xkb_keymap_layout_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
xkb_led_index_t (*xkb_keymap_num_leds_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
const char* (*xkb_keymap_led_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_led_index_t);
xkb_led_index_t (*xkb_keymap_led_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
xkb_layout_index_t (*xkb_keymap_num_layouts_for_key_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
xkb_level_index_t (*xkb_keymap_num_levels_for_key_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t);
size_t (*xkb_keymap_key_get_mods_for_level_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t, xkb_level_index_t, xkb_mod_mask_t*, size_t);
int (*xkb_keymap_key_get_syms_by_level_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t, xkb_level_index_t,const xkb_keysym_t**);
int (*xkb_keymap_key_repeats_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
struct xkb_state* (*xkb_state_new_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
struct xkb_state* (*xkb_state_ref_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
void (*xkb_state_unref_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
struct xkb_keymap* (*xkb_state_get_keymap_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
enum xkb_state_component (*xkb_state_update_key_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,enum xkb_key_direction);
enum xkb_state_component (*xkb_state_update_mask_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
int (*xkb_state_key_get_syms_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,const xkb_keysym_t**);
int (*xkb_state_key_get_utf8_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, char*, size_t);
uint32_t (*xkb_state_key_get_utf32_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
xkb_keysym_t (*xkb_state_key_get_one_sym_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
xkb_layout_index_t (*xkb_state_key_get_layout_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
xkb_level_index_t (*xkb_state_key_get_level_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_layout_index_t);
xkb_mod_mask_t (*xkb_state_serialize_mods_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component);
xkb_layout_index_t (*xkb_state_serialize_layout_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component);
int (*xkb_state_mod_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*,enum xkb_state_component);
int (*xkb_state_mod_names_are_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component,enum xkb_state_match,...);
int (*xkb_state_mod_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_mod_index_t,enum xkb_state_component);
int (*xkb_state_mod_indices_are_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component,enum xkb_state_match,...);
xkb_mod_mask_t (*xkb_state_key_get_consumed_mods2_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,enum xkb_consumed_mode);
xkb_mod_mask_t (*xkb_state_key_get_consumed_mods_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
int (*xkb_state_mod_index_is_consumed2_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_index_t,enum xkb_consumed_mode);
int (*xkb_state_mod_index_is_consumed_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_index_t);
xkb_mod_mask_t (*xkb_state_mod_mask_remove_consumed_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_mask_t);
int (*xkb_state_layout_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*,enum xkb_state_component);
int (*xkb_state_layout_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_layout_index_t,enum xkb_state_component);
int (*xkb_state_led_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*);
int (*xkb_state_led_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_led_index_t);
int initialize_xkbcommon(int verbose) {
void *handle;
char *error;
handle = dlopen("libxkbcommon.so.0", RTLD_LAZY);
if (!handle) {
if (verbose) {
fprintf(stderr, "%s\n", dlerror());
}
return(1);
}
dlerror();
// xkb_keysym_get_name
*(void **) (&xkb_keysym_get_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_get_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keysym_from_name
*(void **) (&xkb_keysym_from_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_from_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keysym_to_utf8
*(void **) (&xkb_keysym_to_utf8_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_to_utf8");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keysym_to_utf32
*(void **) (&xkb_keysym_to_utf32_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_to_utf32");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_utf32_to_keysym
*(void **) (&xkb_utf32_to_keysym_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_utf32_to_keysym");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keysym_to_upper
*(void **) (&xkb_keysym_to_upper_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_to_upper");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keysym_to_lower
*(void **) (&xkb_keysym_to_lower_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keysym_to_lower");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_new
*(void **) (&xkb_context_new_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_new");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_ref
*(void **) (&xkb_context_ref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_ref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_unref
*(void **) (&xkb_context_unref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_unref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_set_user_data
*(void **) (&xkb_context_set_user_data_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_set_user_data");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_get_user_data
*(void **) (&xkb_context_get_user_data_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_get_user_data");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_include_path_append
*(void **) (&xkb_context_include_path_append_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_include_path_append");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_include_path_append_default
*(void **) (&xkb_context_include_path_append_default_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_include_path_append_default");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_include_path_reset_defaults
*(void **) (&xkb_context_include_path_reset_defaults_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_include_path_reset_defaults");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_include_path_clear
*(void **) (&xkb_context_include_path_clear_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_include_path_clear");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_num_include_paths
*(void **) (&xkb_context_num_include_paths_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_num_include_paths");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_include_path_get
*(void **) (&xkb_context_include_path_get_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_include_path_get");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_set_log_level
*(void **) (&xkb_context_set_log_level_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_set_log_level");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_get_log_level
*(void **) (&xkb_context_get_log_level_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_get_log_level");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_set_log_verbosity
*(void **) (&xkb_context_set_log_verbosity_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_set_log_verbosity");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_get_log_verbosity
*(void **) (&xkb_context_get_log_verbosity_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_get_log_verbosity");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_context_set_log_fn
*(void **) (&xkb_context_set_log_fn_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_context_set_log_fn");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_new_from_names
*(void **) (&xkb_keymap_new_from_names_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_new_from_names");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_new_from_file
*(void **) (&xkb_keymap_new_from_file_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_new_from_file");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_new_from_string
*(void **) (&xkb_keymap_new_from_string_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_new_from_string");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_new_from_buffer
*(void **) (&xkb_keymap_new_from_buffer_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_new_from_buffer");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_ref
*(void **) (&xkb_keymap_ref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_ref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_unref
*(void **) (&xkb_keymap_unref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_unref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_get_as_string
*(void **) (&xkb_keymap_get_as_string_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_get_as_string");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_min_keycode
*(void **) (&xkb_keymap_min_keycode_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_min_keycode");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_max_keycode
*(void **) (&xkb_keymap_max_keycode_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_max_keycode");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_for_each
*(void **) (&xkb_keymap_key_for_each_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_for_each");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_get_name
*(void **) (&xkb_keymap_key_get_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_get_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_by_name
*(void **) (&xkb_keymap_key_by_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_by_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_num_mods
*(void **) (&xkb_keymap_num_mods_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_num_mods");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_mod_get_name
*(void **) (&xkb_keymap_mod_get_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_mod_get_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_mod_get_index
*(void **) (&xkb_keymap_mod_get_index_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_mod_get_index");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_num_layouts
*(void **) (&xkb_keymap_num_layouts_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_num_layouts");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_layout_get_name
*(void **) (&xkb_keymap_layout_get_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_layout_get_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_layout_get_index
*(void **) (&xkb_keymap_layout_get_index_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_layout_get_index");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_num_leds
*(void **) (&xkb_keymap_num_leds_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_num_leds");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_led_get_name
*(void **) (&xkb_keymap_led_get_name_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_led_get_name");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_led_get_index
*(void **) (&xkb_keymap_led_get_index_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_led_get_index");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_num_layouts_for_key
*(void **) (&xkb_keymap_num_layouts_for_key_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_num_layouts_for_key");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_num_levels_for_key
*(void **) (&xkb_keymap_num_levels_for_key_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_num_levels_for_key");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_get_mods_for_level
*(void **) (&xkb_keymap_key_get_mods_for_level_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_get_mods_for_level");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_get_syms_by_level
*(void **) (&xkb_keymap_key_get_syms_by_level_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_get_syms_by_level");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_keymap_key_repeats
*(void **) (&xkb_keymap_key_repeats_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_keymap_key_repeats");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_new
*(void **) (&xkb_state_new_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_new");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_ref
*(void **) (&xkb_state_ref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_ref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_unref
*(void **) (&xkb_state_unref_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_unref");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_get_keymap
*(void **) (&xkb_state_get_keymap_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_get_keymap");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_update_key
*(void **) (&xkb_state_update_key_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_update_key");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_update_mask
*(void **) (&xkb_state_update_mask_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_update_mask");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_syms
*(void **) (&xkb_state_key_get_syms_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_syms");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_utf8
*(void **) (&xkb_state_key_get_utf8_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_utf8");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_utf32
*(void **) (&xkb_state_key_get_utf32_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_utf32");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_one_sym
*(void **) (&xkb_state_key_get_one_sym_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_one_sym");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_layout
*(void **) (&xkb_state_key_get_layout_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_layout");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_level
*(void **) (&xkb_state_key_get_level_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_level");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_serialize_mods
*(void **) (&xkb_state_serialize_mods_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_serialize_mods");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_serialize_layout
*(void **) (&xkb_state_serialize_layout_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_serialize_layout");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_name_is_active
*(void **) (&xkb_state_mod_name_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_name_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_names_are_active
*(void **) (&xkb_state_mod_names_are_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_names_are_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_index_is_active
*(void **) (&xkb_state_mod_index_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_index_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_indices_are_active
*(void **) (&xkb_state_mod_indices_are_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_indices_are_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_consumed_mods2
*(void **) (&xkb_state_key_get_consumed_mods2_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_consumed_mods2");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_key_get_consumed_mods
*(void **) (&xkb_state_key_get_consumed_mods_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_key_get_consumed_mods");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_index_is_consumed2
*(void **) (&xkb_state_mod_index_is_consumed2_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_index_is_consumed2");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_index_is_consumed
*(void **) (&xkb_state_mod_index_is_consumed_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_index_is_consumed");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_mod_mask_remove_consumed
*(void **) (&xkb_state_mod_mask_remove_consumed_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_mod_mask_remove_consumed");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_layout_name_is_active
*(void **) (&xkb_state_layout_name_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_layout_name_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_layout_index_is_active
*(void **) (&xkb_state_layout_index_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_layout_index_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_led_name_is_active
*(void **) (&xkb_state_led_name_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_led_name_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
// xkb_state_led_index_is_active
*(void **) (&xkb_state_led_index_is_active_dylibloader_wrapper_xkbcommon) = dlsym(handle, "xkb_state_led_index_is_active");
if (verbose) {
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
}
}
return 0;
}

View File

@ -0,0 +1,322 @@
#ifndef DYLIBLOAD_WRAPPER_XKBCOMMON
#define DYLIBLOAD_WRAPPER_XKBCOMMON
// This file is generated. Do not edit!
// see https://github.com/hpvb/dynload-wrapper for details
// generated by ./generate-wrapper.py 0.3 on 2023-01-23 14:25:23
// flags: ./generate-wrapper.py --include /usr/include/xkbcommon/xkbcommon.h --sys-include <xkbcommon/xkbcommon.h> --soname libxkbcommon.so.0 --init-name xkbcommon --output-header xkbcommon-so_wrap.h --output-implementation xkbcommon-so_wrap.c
//
#include <stdint.h>
#define xkb_keysym_get_name xkb_keysym_get_name_dylibloader_orig_xkbcommon
#define xkb_keysym_from_name xkb_keysym_from_name_dylibloader_orig_xkbcommon
#define xkb_keysym_to_utf8 xkb_keysym_to_utf8_dylibloader_orig_xkbcommon
#define xkb_keysym_to_utf32 xkb_keysym_to_utf32_dylibloader_orig_xkbcommon
#define xkb_utf32_to_keysym xkb_utf32_to_keysym_dylibloader_orig_xkbcommon
#define xkb_keysym_to_upper xkb_keysym_to_upper_dylibloader_orig_xkbcommon
#define xkb_keysym_to_lower xkb_keysym_to_lower_dylibloader_orig_xkbcommon
#define xkb_context_new xkb_context_new_dylibloader_orig_xkbcommon
#define xkb_context_ref xkb_context_ref_dylibloader_orig_xkbcommon
#define xkb_context_unref xkb_context_unref_dylibloader_orig_xkbcommon
#define xkb_context_set_user_data xkb_context_set_user_data_dylibloader_orig_xkbcommon
#define xkb_context_get_user_data xkb_context_get_user_data_dylibloader_orig_xkbcommon
#define xkb_context_include_path_append xkb_context_include_path_append_dylibloader_orig_xkbcommon
#define xkb_context_include_path_append_default xkb_context_include_path_append_default_dylibloader_orig_xkbcommon
#define xkb_context_include_path_reset_defaults xkb_context_include_path_reset_defaults_dylibloader_orig_xkbcommon
#define xkb_context_include_path_clear xkb_context_include_path_clear_dylibloader_orig_xkbcommon
#define xkb_context_num_include_paths xkb_context_num_include_paths_dylibloader_orig_xkbcommon
#define xkb_context_include_path_get xkb_context_include_path_get_dylibloader_orig_xkbcommon
#define xkb_context_set_log_level xkb_context_set_log_level_dylibloader_orig_xkbcommon
#define xkb_context_get_log_level xkb_context_get_log_level_dylibloader_orig_xkbcommon
#define xkb_context_set_log_verbosity xkb_context_set_log_verbosity_dylibloader_orig_xkbcommon
#define xkb_context_get_log_verbosity xkb_context_get_log_verbosity_dylibloader_orig_xkbcommon
#define xkb_context_set_log_fn xkb_context_set_log_fn_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_names xkb_keymap_new_from_names_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_file xkb_keymap_new_from_file_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_string xkb_keymap_new_from_string_dylibloader_orig_xkbcommon
#define xkb_keymap_new_from_buffer xkb_keymap_new_from_buffer_dylibloader_orig_xkbcommon
#define xkb_keymap_ref xkb_keymap_ref_dylibloader_orig_xkbcommon
#define xkb_keymap_unref xkb_keymap_unref_dylibloader_orig_xkbcommon
#define xkb_keymap_get_as_string xkb_keymap_get_as_string_dylibloader_orig_xkbcommon
#define xkb_keymap_min_keycode xkb_keymap_min_keycode_dylibloader_orig_xkbcommon
#define xkb_keymap_max_keycode xkb_keymap_max_keycode_dylibloader_orig_xkbcommon
#define xkb_keymap_key_for_each xkb_keymap_key_for_each_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_name xkb_keymap_key_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_key_by_name xkb_keymap_key_by_name_dylibloader_orig_xkbcommon
#define xkb_keymap_num_mods xkb_keymap_num_mods_dylibloader_orig_xkbcommon
#define xkb_keymap_mod_get_name xkb_keymap_mod_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_mod_get_index xkb_keymap_mod_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_layouts xkb_keymap_num_layouts_dylibloader_orig_xkbcommon
#define xkb_keymap_layout_get_name xkb_keymap_layout_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_layout_get_index xkb_keymap_layout_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_leds xkb_keymap_num_leds_dylibloader_orig_xkbcommon
#define xkb_keymap_led_get_name xkb_keymap_led_get_name_dylibloader_orig_xkbcommon
#define xkb_keymap_led_get_index xkb_keymap_led_get_index_dylibloader_orig_xkbcommon
#define xkb_keymap_num_layouts_for_key xkb_keymap_num_layouts_for_key_dylibloader_orig_xkbcommon
#define xkb_keymap_num_levels_for_key xkb_keymap_num_levels_for_key_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_mods_for_level xkb_keymap_key_get_mods_for_level_dylibloader_orig_xkbcommon
#define xkb_keymap_key_get_syms_by_level xkb_keymap_key_get_syms_by_level_dylibloader_orig_xkbcommon
#define xkb_keymap_key_repeats xkb_keymap_key_repeats_dylibloader_orig_xkbcommon
#define xkb_state_new xkb_state_new_dylibloader_orig_xkbcommon
#define xkb_state_ref xkb_state_ref_dylibloader_orig_xkbcommon
#define xkb_state_unref xkb_state_unref_dylibloader_orig_xkbcommon
#define xkb_state_get_keymap xkb_state_get_keymap_dylibloader_orig_xkbcommon
#define xkb_state_update_key xkb_state_update_key_dylibloader_orig_xkbcommon
#define xkb_state_update_mask xkb_state_update_mask_dylibloader_orig_xkbcommon
#define xkb_state_key_get_syms xkb_state_key_get_syms_dylibloader_orig_xkbcommon
#define xkb_state_key_get_utf8 xkb_state_key_get_utf8_dylibloader_orig_xkbcommon
#define xkb_state_key_get_utf32 xkb_state_key_get_utf32_dylibloader_orig_xkbcommon
#define xkb_state_key_get_one_sym xkb_state_key_get_one_sym_dylibloader_orig_xkbcommon
#define xkb_state_key_get_layout xkb_state_key_get_layout_dylibloader_orig_xkbcommon
#define xkb_state_key_get_level xkb_state_key_get_level_dylibloader_orig_xkbcommon
#define xkb_state_serialize_mods xkb_state_serialize_mods_dylibloader_orig_xkbcommon
#define xkb_state_serialize_layout xkb_state_serialize_layout_dylibloader_orig_xkbcommon
#define xkb_state_mod_name_is_active xkb_state_mod_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_names_are_active xkb_state_mod_names_are_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_active xkb_state_mod_index_is_active_dylibloader_orig_xkbcommon
#define xkb_state_mod_indices_are_active xkb_state_mod_indices_are_active_dylibloader_orig_xkbcommon
#define xkb_state_key_get_consumed_mods2 xkb_state_key_get_consumed_mods2_dylibloader_orig_xkbcommon
#define xkb_state_key_get_consumed_mods xkb_state_key_get_consumed_mods_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_consumed2 xkb_state_mod_index_is_consumed2_dylibloader_orig_xkbcommon
#define xkb_state_mod_index_is_consumed xkb_state_mod_index_is_consumed_dylibloader_orig_xkbcommon
#define xkb_state_mod_mask_remove_consumed xkb_state_mod_mask_remove_consumed_dylibloader_orig_xkbcommon
#define xkb_state_layout_name_is_active xkb_state_layout_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_layout_index_is_active xkb_state_layout_index_is_active_dylibloader_orig_xkbcommon
#define xkb_state_led_name_is_active xkb_state_led_name_is_active_dylibloader_orig_xkbcommon
#define xkb_state_led_index_is_active xkb_state_led_index_is_active_dylibloader_orig_xkbcommon
#include <xkbcommon/xkbcommon.h>
#undef xkb_keysym_get_name
#undef xkb_keysym_from_name
#undef xkb_keysym_to_utf8
#undef xkb_keysym_to_utf32
#undef xkb_utf32_to_keysym
#undef xkb_keysym_to_upper
#undef xkb_keysym_to_lower
#undef xkb_context_new
#undef xkb_context_ref
#undef xkb_context_unref
#undef xkb_context_set_user_data
#undef xkb_context_get_user_data
#undef xkb_context_include_path_append
#undef xkb_context_include_path_append_default
#undef xkb_context_include_path_reset_defaults
#undef xkb_context_include_path_clear
#undef xkb_context_num_include_paths
#undef xkb_context_include_path_get
#undef xkb_context_set_log_level
#undef xkb_context_get_log_level
#undef xkb_context_set_log_verbosity
#undef xkb_context_get_log_verbosity
#undef xkb_context_set_log_fn
#undef xkb_keymap_new_from_names
#undef xkb_keymap_new_from_file
#undef xkb_keymap_new_from_string
#undef xkb_keymap_new_from_buffer
#undef xkb_keymap_ref
#undef xkb_keymap_unref
#undef xkb_keymap_get_as_string
#undef xkb_keymap_min_keycode
#undef xkb_keymap_max_keycode
#undef xkb_keymap_key_for_each
#undef xkb_keymap_key_get_name
#undef xkb_keymap_key_by_name
#undef xkb_keymap_num_mods
#undef xkb_keymap_mod_get_name
#undef xkb_keymap_mod_get_index
#undef xkb_keymap_num_layouts
#undef xkb_keymap_layout_get_name
#undef xkb_keymap_layout_get_index
#undef xkb_keymap_num_leds
#undef xkb_keymap_led_get_name
#undef xkb_keymap_led_get_index
#undef xkb_keymap_num_layouts_for_key
#undef xkb_keymap_num_levels_for_key
#undef xkb_keymap_key_get_mods_for_level
#undef xkb_keymap_key_get_syms_by_level
#undef xkb_keymap_key_repeats
#undef xkb_state_new
#undef xkb_state_ref
#undef xkb_state_unref
#undef xkb_state_get_keymap
#undef xkb_state_update_key
#undef xkb_state_update_mask
#undef xkb_state_key_get_syms
#undef xkb_state_key_get_utf8
#undef xkb_state_key_get_utf32
#undef xkb_state_key_get_one_sym
#undef xkb_state_key_get_layout
#undef xkb_state_key_get_level
#undef xkb_state_serialize_mods
#undef xkb_state_serialize_layout
#undef xkb_state_mod_name_is_active
#undef xkb_state_mod_names_are_active
#undef xkb_state_mod_index_is_active
#undef xkb_state_mod_indices_are_active
#undef xkb_state_key_get_consumed_mods2
#undef xkb_state_key_get_consumed_mods
#undef xkb_state_mod_index_is_consumed2
#undef xkb_state_mod_index_is_consumed
#undef xkb_state_mod_mask_remove_consumed
#undef xkb_state_layout_name_is_active
#undef xkb_state_layout_index_is_active
#undef xkb_state_led_name_is_active
#undef xkb_state_led_index_is_active
#ifdef __cplusplus
extern "C" {
#endif
#define xkb_keysym_get_name xkb_keysym_get_name_dylibloader_wrapper_xkbcommon
#define xkb_keysym_from_name xkb_keysym_from_name_dylibloader_wrapper_xkbcommon
#define xkb_keysym_to_utf8 xkb_keysym_to_utf8_dylibloader_wrapper_xkbcommon
#define xkb_keysym_to_utf32 xkb_keysym_to_utf32_dylibloader_wrapper_xkbcommon
#define xkb_utf32_to_keysym xkb_utf32_to_keysym_dylibloader_wrapper_xkbcommon
#define xkb_keysym_to_upper xkb_keysym_to_upper_dylibloader_wrapper_xkbcommon
#define xkb_keysym_to_lower xkb_keysym_to_lower_dylibloader_wrapper_xkbcommon
#define xkb_context_new xkb_context_new_dylibloader_wrapper_xkbcommon
#define xkb_context_ref xkb_context_ref_dylibloader_wrapper_xkbcommon
#define xkb_context_unref xkb_context_unref_dylibloader_wrapper_xkbcommon
#define xkb_context_set_user_data xkb_context_set_user_data_dylibloader_wrapper_xkbcommon
#define xkb_context_get_user_data xkb_context_get_user_data_dylibloader_wrapper_xkbcommon
#define xkb_context_include_path_append xkb_context_include_path_append_dylibloader_wrapper_xkbcommon
#define xkb_context_include_path_append_default xkb_context_include_path_append_default_dylibloader_wrapper_xkbcommon
#define xkb_context_include_path_reset_defaults xkb_context_include_path_reset_defaults_dylibloader_wrapper_xkbcommon
#define xkb_context_include_path_clear xkb_context_include_path_clear_dylibloader_wrapper_xkbcommon
#define xkb_context_num_include_paths xkb_context_num_include_paths_dylibloader_wrapper_xkbcommon
#define xkb_context_include_path_get xkb_context_include_path_get_dylibloader_wrapper_xkbcommon
#define xkb_context_set_log_level xkb_context_set_log_level_dylibloader_wrapper_xkbcommon
#define xkb_context_get_log_level xkb_context_get_log_level_dylibloader_wrapper_xkbcommon
#define xkb_context_set_log_verbosity xkb_context_set_log_verbosity_dylibloader_wrapper_xkbcommon
#define xkb_context_get_log_verbosity xkb_context_get_log_verbosity_dylibloader_wrapper_xkbcommon
#define xkb_context_set_log_fn xkb_context_set_log_fn_dylibloader_wrapper_xkbcommon
#define xkb_keymap_new_from_names xkb_keymap_new_from_names_dylibloader_wrapper_xkbcommon
#define xkb_keymap_new_from_file xkb_keymap_new_from_file_dylibloader_wrapper_xkbcommon
#define xkb_keymap_new_from_string xkb_keymap_new_from_string_dylibloader_wrapper_xkbcommon
#define xkb_keymap_new_from_buffer xkb_keymap_new_from_buffer_dylibloader_wrapper_xkbcommon
#define xkb_keymap_ref xkb_keymap_ref_dylibloader_wrapper_xkbcommon
#define xkb_keymap_unref xkb_keymap_unref_dylibloader_wrapper_xkbcommon
#define xkb_keymap_get_as_string xkb_keymap_get_as_string_dylibloader_wrapper_xkbcommon
#define xkb_keymap_min_keycode xkb_keymap_min_keycode_dylibloader_wrapper_xkbcommon
#define xkb_keymap_max_keycode xkb_keymap_max_keycode_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_for_each xkb_keymap_key_for_each_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_get_name xkb_keymap_key_get_name_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_by_name xkb_keymap_key_by_name_dylibloader_wrapper_xkbcommon
#define xkb_keymap_num_mods xkb_keymap_num_mods_dylibloader_wrapper_xkbcommon
#define xkb_keymap_mod_get_name xkb_keymap_mod_get_name_dylibloader_wrapper_xkbcommon
#define xkb_keymap_mod_get_index xkb_keymap_mod_get_index_dylibloader_wrapper_xkbcommon
#define xkb_keymap_num_layouts xkb_keymap_num_layouts_dylibloader_wrapper_xkbcommon
#define xkb_keymap_layout_get_name xkb_keymap_layout_get_name_dylibloader_wrapper_xkbcommon
#define xkb_keymap_layout_get_index xkb_keymap_layout_get_index_dylibloader_wrapper_xkbcommon
#define xkb_keymap_num_leds xkb_keymap_num_leds_dylibloader_wrapper_xkbcommon
#define xkb_keymap_led_get_name xkb_keymap_led_get_name_dylibloader_wrapper_xkbcommon
#define xkb_keymap_led_get_index xkb_keymap_led_get_index_dylibloader_wrapper_xkbcommon
#define xkb_keymap_num_layouts_for_key xkb_keymap_num_layouts_for_key_dylibloader_wrapper_xkbcommon
#define xkb_keymap_num_levels_for_key xkb_keymap_num_levels_for_key_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_get_mods_for_level xkb_keymap_key_get_mods_for_level_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_get_syms_by_level xkb_keymap_key_get_syms_by_level_dylibloader_wrapper_xkbcommon
#define xkb_keymap_key_repeats xkb_keymap_key_repeats_dylibloader_wrapper_xkbcommon
#define xkb_state_new xkb_state_new_dylibloader_wrapper_xkbcommon
#define xkb_state_ref xkb_state_ref_dylibloader_wrapper_xkbcommon
#define xkb_state_unref xkb_state_unref_dylibloader_wrapper_xkbcommon
#define xkb_state_get_keymap xkb_state_get_keymap_dylibloader_wrapper_xkbcommon
#define xkb_state_update_key xkb_state_update_key_dylibloader_wrapper_xkbcommon
#define xkb_state_update_mask xkb_state_update_mask_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_syms xkb_state_key_get_syms_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_utf8 xkb_state_key_get_utf8_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_utf32 xkb_state_key_get_utf32_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_one_sym xkb_state_key_get_one_sym_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_layout xkb_state_key_get_layout_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_level xkb_state_key_get_level_dylibloader_wrapper_xkbcommon
#define xkb_state_serialize_mods xkb_state_serialize_mods_dylibloader_wrapper_xkbcommon
#define xkb_state_serialize_layout xkb_state_serialize_layout_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_name_is_active xkb_state_mod_name_is_active_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_names_are_active xkb_state_mod_names_are_active_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_index_is_active xkb_state_mod_index_is_active_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_indices_are_active xkb_state_mod_indices_are_active_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_consumed_mods2 xkb_state_key_get_consumed_mods2_dylibloader_wrapper_xkbcommon
#define xkb_state_key_get_consumed_mods xkb_state_key_get_consumed_mods_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_index_is_consumed2 xkb_state_mod_index_is_consumed2_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_index_is_consumed xkb_state_mod_index_is_consumed_dylibloader_wrapper_xkbcommon
#define xkb_state_mod_mask_remove_consumed xkb_state_mod_mask_remove_consumed_dylibloader_wrapper_xkbcommon
#define xkb_state_layout_name_is_active xkb_state_layout_name_is_active_dylibloader_wrapper_xkbcommon
#define xkb_state_layout_index_is_active xkb_state_layout_index_is_active_dylibloader_wrapper_xkbcommon
#define xkb_state_led_name_is_active xkb_state_led_name_is_active_dylibloader_wrapper_xkbcommon
#define xkb_state_led_index_is_active xkb_state_led_index_is_active_dylibloader_wrapper_xkbcommon
extern int (*xkb_keysym_get_name_dylibloader_wrapper_xkbcommon)( xkb_keysym_t, char*, size_t);
extern xkb_keysym_t (*xkb_keysym_from_name_dylibloader_wrapper_xkbcommon)(const char*,enum xkb_keysym_flags);
extern int (*xkb_keysym_to_utf8_dylibloader_wrapper_xkbcommon)( xkb_keysym_t, char*, size_t);
extern uint32_t (*xkb_keysym_to_utf32_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
extern xkb_keysym_t (*xkb_utf32_to_keysym_dylibloader_wrapper_xkbcommon)( uint32_t);
extern xkb_keysym_t (*xkb_keysym_to_upper_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
extern xkb_keysym_t (*xkb_keysym_to_lower_dylibloader_wrapper_xkbcommon)( xkb_keysym_t);
extern struct xkb_context* (*xkb_context_new_dylibloader_wrapper_xkbcommon)(enum xkb_context_flags);
extern struct xkb_context* (*xkb_context_ref_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern void (*xkb_context_unref_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern void (*xkb_context_set_user_data_dylibloader_wrapper_xkbcommon)(struct xkb_context*, void*);
extern void* (*xkb_context_get_user_data_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern int (*xkb_context_include_path_append_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*);
extern int (*xkb_context_include_path_append_default_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern int (*xkb_context_include_path_reset_defaults_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern void (*xkb_context_include_path_clear_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern unsigned int (*xkb_context_num_include_paths_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern const char* (*xkb_context_include_path_get_dylibloader_wrapper_xkbcommon)(struct xkb_context*, unsigned int);
extern void (*xkb_context_set_log_level_dylibloader_wrapper_xkbcommon)(struct xkb_context*,enum xkb_log_level);
extern enum xkb_log_level (*xkb_context_get_log_level_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern void (*xkb_context_set_log_verbosity_dylibloader_wrapper_xkbcommon)(struct xkb_context*, int);
extern int (*xkb_context_get_log_verbosity_dylibloader_wrapper_xkbcommon)(struct xkb_context*);
extern void (*xkb_context_set_log_fn_dylibloader_wrapper_xkbcommon)(struct xkb_context*, void*);
extern struct xkb_keymap* (*xkb_keymap_new_from_names_dylibloader_wrapper_xkbcommon)(struct xkb_context*,struct xkb_rule_names*,enum xkb_keymap_compile_flags);
extern struct xkb_keymap* (*xkb_keymap_new_from_file_dylibloader_wrapper_xkbcommon)(struct xkb_context*, FILE*,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
extern struct xkb_keymap* (*xkb_keymap_new_from_string_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
extern struct xkb_keymap* (*xkb_keymap_new_from_buffer_dylibloader_wrapper_xkbcommon)(struct xkb_context*,const char*, size_t,enum xkb_keymap_format,enum xkb_keymap_compile_flags);
extern struct xkb_keymap* (*xkb_keymap_ref_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern void (*xkb_keymap_unref_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern char* (*xkb_keymap_get_as_string_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,enum xkb_keymap_format);
extern xkb_keycode_t (*xkb_keymap_min_keycode_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern xkb_keycode_t (*xkb_keymap_max_keycode_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern void (*xkb_keymap_key_for_each_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keymap_key_iter_t, void*);
extern const char* (*xkb_keymap_key_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
extern xkb_keycode_t (*xkb_keymap_key_by_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
extern xkb_mod_index_t (*xkb_keymap_num_mods_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern const char* (*xkb_keymap_mod_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_mod_index_t);
extern xkb_mod_index_t (*xkb_keymap_mod_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
extern xkb_layout_index_t (*xkb_keymap_num_layouts_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern const char* (*xkb_keymap_layout_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_layout_index_t);
extern xkb_layout_index_t (*xkb_keymap_layout_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
extern xkb_led_index_t (*xkb_keymap_num_leds_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern const char* (*xkb_keymap_led_get_name_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_led_index_t);
extern xkb_led_index_t (*xkb_keymap_led_get_index_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*,const char*);
extern xkb_layout_index_t (*xkb_keymap_num_layouts_for_key_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
extern xkb_level_index_t (*xkb_keymap_num_levels_for_key_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t);
extern size_t (*xkb_keymap_key_get_mods_for_level_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t, xkb_level_index_t, xkb_mod_mask_t*, size_t);
extern int (*xkb_keymap_key_get_syms_by_level_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t, xkb_layout_index_t, xkb_level_index_t,const xkb_keysym_t**);
extern int (*xkb_keymap_key_repeats_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*, xkb_keycode_t);
extern struct xkb_state* (*xkb_state_new_dylibloader_wrapper_xkbcommon)(struct xkb_keymap*);
extern struct xkb_state* (*xkb_state_ref_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
extern void (*xkb_state_unref_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
extern struct xkb_keymap* (*xkb_state_get_keymap_dylibloader_wrapper_xkbcommon)(struct xkb_state*);
extern enum xkb_state_component (*xkb_state_update_key_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,enum xkb_key_direction);
extern enum xkb_state_component (*xkb_state_update_mask_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
extern int (*xkb_state_key_get_syms_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,const xkb_keysym_t**);
extern int (*xkb_state_key_get_utf8_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, char*, size_t);
extern uint32_t (*xkb_state_key_get_utf32_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
extern xkb_keysym_t (*xkb_state_key_get_one_sym_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
extern xkb_layout_index_t (*xkb_state_key_get_layout_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
extern xkb_level_index_t (*xkb_state_key_get_level_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_layout_index_t);
extern xkb_mod_mask_t (*xkb_state_serialize_mods_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component);
extern xkb_layout_index_t (*xkb_state_serialize_layout_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component);
extern int (*xkb_state_mod_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*,enum xkb_state_component);
extern int (*xkb_state_mod_names_are_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component,enum xkb_state_match,...);
extern int (*xkb_state_mod_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_mod_index_t,enum xkb_state_component);
extern int (*xkb_state_mod_indices_are_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,enum xkb_state_component,enum xkb_state_match,...);
extern xkb_mod_mask_t (*xkb_state_key_get_consumed_mods2_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t,enum xkb_consumed_mode);
extern xkb_mod_mask_t (*xkb_state_key_get_consumed_mods_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t);
extern int (*xkb_state_mod_index_is_consumed2_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_index_t,enum xkb_consumed_mode);
extern int (*xkb_state_mod_index_is_consumed_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_index_t);
extern xkb_mod_mask_t (*xkb_state_mod_mask_remove_consumed_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_keycode_t, xkb_mod_mask_t);
extern int (*xkb_state_layout_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*,enum xkb_state_component);
extern int (*xkb_state_layout_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_layout_index_t,enum xkb_state_component);
extern int (*xkb_state_led_name_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*,const char*);
extern int (*xkb_state_led_index_is_active_dylibloader_wrapper_xkbcommon)(struct xkb_state*, xkb_led_index_t);
int initialize_xkbcommon(int verbose);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -44,12 +44,12 @@ class KeyMappingX11 {
KeyMappingX11() {}
public:
static void initialize();
static Key get_keycode(KeySym p_keysym);
static unsigned int get_xlibcode(Key p_keysym);
static Key get_scancode(unsigned int p_code);
static KeySym get_keysym(Key p_code);
static unsigned int get_unicode_from_keysym(KeySym p_keysym);
static KeySym get_keysym_from_unicode(unsigned int p_unicode);
static char32_t get_unicode_from_keysym(KeySym p_keysym);
};
#endif // KEY_MAPPING_X11_H

View File

@ -69,6 +69,7 @@ public:
bool raw = false;
Key keycode = Key::NONE;
Key physical_keycode = Key::NONE;
Key key_label = Key::NONE;
uint32_t unicode = 0;
};
@ -201,8 +202,6 @@ private:
Point2i _get_native_screen_position(int p_screen) const;
static void _displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplayChangeSummaryFlags flags, void *user_info);
WindowID _get_focused_window_or_popup() const;
static void _dispatch_input_events(const Ref<InputEvent> &p_event);
void _dispatch_input_event(const Ref<InputEvent> &p_event);
void _push_input(const Ref<InputEvent> &p_event);
@ -229,6 +228,7 @@ public:
void get_key_modifier_state(unsigned int p_macos_state, Ref<InputEventWithModifiers> r_state) const;
void update_mouse_pos(WindowData &p_wd, NSPoint p_location_in_window);
void push_to_key_event_buffer(const KeyEvent &p_event);
void pop_last_key_event();
void update_im_text(const Point2i &p_selection, const String &p_text);
void set_last_focused_window(WindowID p_window);
bool mouse_process_popups(bool p_close = false);
@ -237,6 +237,7 @@ public:
void set_is_resizing(bool p_is_resizing);
bool get_is_resizing() const;
void reparent_check(WindowID p_window);
WindowID _get_focused_window_or_popup() const;
void window_update(WindowID p_window);
void window_destroy(WindowID p_window);

View File

@ -434,7 +434,8 @@ void DisplayServerMacOS::_process_key_events() {
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
k->set_keycode(ke.keycode);
k->set_physical_keycode((Key)ke.physical_keycode);
k->set_physical_keycode(ke.physical_keycode);
k->set_key_label(ke.key_label);
k->set_unicode(ke.unicode);
_push_input(k);
@ -449,6 +450,7 @@ void DisplayServerMacOS::_process_key_events() {
k->set_echo(ke.echo);
k->set_keycode(Key::NONE);
k->set_physical_keycode(Key::NONE);
k->set_key_label(Key::NONE);
k->set_unicode(ke.unicode);
_push_input(k);
@ -461,7 +463,8 @@ void DisplayServerMacOS::_process_key_events() {
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
k->set_keycode(ke.keycode);
k->set_physical_keycode((Key)ke.physical_keycode);
k->set_physical_keycode(ke.physical_keycode);
k->set_key_label(ke.key_label);
if (i + 1 < key_event_pos && key_event_buffer[i + 1].keycode == Key::NONE) {
k->set_unicode(key_event_buffer[i + 1].unicode);
@ -633,6 +636,7 @@ void DisplayServerMacOS::send_event(NSEvent *p_event) {
k->set_pressed(true);
k->set_keycode(Key::PERIOD);
k->set_physical_keycode(Key::PERIOD);
k->set_key_label(Key::PERIOD);
k->set_echo([p_event isARepeat]);
Input::get_singleton()->parse_input_event(k);
@ -674,6 +678,12 @@ void DisplayServerMacOS::update_mouse_pos(DisplayServerMacOS::WindowData &p_wd,
Input::get_singleton()->set_mouse_position(p_wd.mouse_pos);
}
void DisplayServerMacOS::pop_last_key_event() {
if (key_event_pos > 0) {
key_event_pos--;
}
}
void DisplayServerMacOS::push_to_key_event_buffer(const DisplayServerMacOS::KeyEvent &p_event) {
if (key_event_pos >= key_event_buffer.size()) {
key_event_buffer.resize(1 + key_event_pos);
@ -3451,14 +3461,14 @@ String DisplayServerMacOS::keyboard_get_layout_name(int p_index) const {
}
Key DisplayServerMacOS::keyboard_get_keycode_from_physical(Key p_keycode) const {
if (p_keycode == Key::PAUSE) {
if (p_keycode == Key::PAUSE || p_keycode == Key::NONE) {
return p_keycode;
}
Key modifiers = p_keycode & KeyModifierMask::MODIFIER_MASK;
Key keycode_no_mod = p_keycode & KeyModifierMask::CODE_MASK;
unsigned int macos_keycode = KeyMappingMacOS::unmap_key((Key)keycode_no_mod);
return (Key)(KeyMappingMacOS::remap_key(macos_keycode, 0) | modifiers);
unsigned int macos_keycode = KeyMappingMacOS::unmap_key(keycode_no_mod);
return (Key)(KeyMappingMacOS::remap_key(macos_keycode, 0, false) | modifiers);
}
void DisplayServerMacOS::process_events() {
@ -3770,6 +3780,8 @@ bool DisplayServerMacOS::mouse_process_popups(bool p_close) {
}
DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
KeyMappingMacOS::initialize();
Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);
r_error = OK;

View File

@ -35,6 +35,7 @@
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/ev_keymap.h>
@interface GodotApplication : NSApplication
@end

View File

@ -34,7 +34,81 @@
@implementation GodotApplication
- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat {
Key keycode = Key::NONE;
switch (key) {
case NX_KEYTYPE_SOUND_UP: {
keycode = Key::VOLUMEUP;
} break;
case NX_KEYTYPE_SOUND_DOWN: {
keycode = Key::VOLUMEUP;
} break;
//NX_KEYTYPE_BRIGHTNESS_UP
//NX_KEYTYPE_BRIGHTNESS_DOWN
case NX_KEYTYPE_CAPS_LOCK: {
keycode = Key::CAPSLOCK;
} break;
case NX_KEYTYPE_HELP: {
keycode = Key::HELP;
} break;
case NX_POWER_KEY: {
keycode = Key::STANDBY;
} break;
case NX_KEYTYPE_MUTE: {
keycode = Key::VOLUMEMUTE;
} break;
//NX_KEYTYPE_CONTRAST_UP
//NX_KEYTYPE_CONTRAST_DOWN
//NX_KEYTYPE_LAUNCH_PANEL
//NX_KEYTYPE_EJECT
//NX_KEYTYPE_VIDMIRROR
//NX_KEYTYPE_FAST
//NX_KEYTYPE_REWIND
//NX_KEYTYPE_ILLUMINATION_UP
//NX_KEYTYPE_ILLUMINATION_DOWN
//NX_KEYTYPE_ILLUMINATION_TOGGLE
case NX_KEYTYPE_PLAY: {
keycode = Key::MEDIAPLAY;
} break;
case NX_KEYTYPE_NEXT: {
keycode = Key::MEDIANEXT;
} break;
case NX_KEYTYPE_PREVIOUS: {
keycode = Key::MEDIAPREVIOUS;
} break;
default: {
keycode = Key::NONE;
} break;
}
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
if (ds && keycode != Key::NONE) {
DisplayServerMacOS::KeyEvent ke;
ke.window_id = ds->_get_focused_window_or_popup();
ke.macos_state = 0;
ke.pressed = state;
ke.echo = repeat;
ke.keycode = keycode;
ke.physical_keycode = keycode;
ke.key_label = keycode;
ke.unicode = 0;
ke.raw = true;
ds->push_to_key_event_buffer(ke);
}
}
- (void)sendEvent:(NSEvent *)event {
if ([event type] == NSSystemDefined && [event subtype] == 8) {
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
int keyRepeat = (keyFlags & 0x1);
[self mediaKeyEvent:keyCode state:keyState repeat:keyRepeat];
}
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
if (ds) {
if ([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeRightMouseDown || [event type] == NSEventTypeOtherMouseDown) {

View File

@ -64,6 +64,7 @@
bool mouse_down_control;
bool ignore_momentum_scroll;
bool last_pen_inverted;
bool ime_suppress_next_keyup;
id layer_delegate;
}

View File

@ -185,6 +185,7 @@
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
if (wd.im_active) {
ime_input_event_in_progress = true;
ds->pop_last_key_event();
ds->update_im_text(Point2i(selectedRange.location, selectedRange.length), String::utf8([[marked_text mutableString] UTF8String]));
}
}
@ -194,6 +195,9 @@
}
- (void)unmarkText {
if (ime_input_event_in_progress) {
ime_suppress_next_keyup = true;
}
ime_input_event_in_progress = false;
[[marked_text mutableString] setString:@""];
@ -245,8 +249,6 @@
}
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange {
NSEvent *event = [NSApp currentEvent];
NSString *characters;
if ([aString isKindOfClass:[NSAttributedString class]]) {
characters = [aString string];
@ -284,13 +286,14 @@
DisplayServerMacOS::KeyEvent ke;
ke.window_id = window_id;
ke.macos_state = [event modifierFlags];
ke.macos_state = 0;
ke.pressed = true;
ke.echo = false;
ke.raw = false; // IME input event.
ke.keycode = Key::NONE;
ke.physical_keycode = Key::NONE;
ke.unicode = codepoint;
ke.key_label = Key::NONE;
ke.unicode = fix_unicode(codepoint);
ds->push_to_key_event_buffer(ke);
}
@ -584,7 +587,7 @@
NSString *characters = [event characters];
NSUInteger length = [characters length];
if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]))) {
if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true))) {
// Fallback unicode character handler used if IME is not active.
Char16String text;
text.resize([characters length] + 1);
@ -602,10 +605,11 @@
ke.macos_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]);
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false);
ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]);
ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true);
ke.unicode = fix_unicode(codepoint);
ke.raw = true;
ke.unicode = codepoint;
ds->push_to_key_event_buffer(ke);
}
@ -616,10 +620,11 @@
ke.macos_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]);
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false);
ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]);
ke.raw = false;
ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true);
ke.unicode = 0;
ke.raw = false;
ds->push_to_key_event_buffer(ke);
}
@ -638,8 +643,6 @@
}
ignore_momentum_scroll = true;
// Ignore all input if IME input is in progress
if (!ime_input_event_in_progress) {
DisplayServerMacOS::KeyEvent ke;
ke.window_id = window_id;
@ -682,12 +685,12 @@
}
ke.macos_state = mod;
ke.keycode = KeyMappingMacOS::remap_key(key, mod);
ke.keycode = KeyMappingMacOS::remap_key(key, mod, false);
ke.physical_keycode = KeyMappingMacOS::translate_key(key);
ke.key_label = KeyMappingMacOS::remap_key(key, mod, true);
ke.unicode = 0;
ds->push_to_key_event_buffer(ke);
}
}
- (void)keyUp:(NSEvent *)event {
@ -696,52 +699,27 @@
return;
}
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
// Ignore all input if IME input is in progress.
if (ime_suppress_next_keyup) {
ime_suppress_next_keyup = false;
return;
}
if (!ime_input_event_in_progress) {
NSString *characters = [event characters];
NSUInteger length = [characters length];
// Fallback unicode character handler used if IME is not active.
if (!wd.im_active && length > 0 && keycode_has_unicode(KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]))) {
Char16String text;
text.resize([characters length] + 1);
[characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])];
String u32text;
u32text.parse_utf16(text.ptr(), text.length());
for (int i = 0; i < u32text.length(); i++) {
const char32_t codepoint = u32text[i];
DisplayServerMacOS::KeyEvent ke;
ke.window_id = window_id;
ke.macos_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]);
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], false);
ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]);
ke.raw = true;
ke.unicode = codepoint;
ds->push_to_key_event_buffer(ke);
}
} else {
DisplayServerMacOS::KeyEvent ke;
ke.window_id = window_id;
ke.macos_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
ke.keycode = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags]);
ke.physical_keycode = KeyMappingMacOS::translate_key([event keyCode]);
ke.raw = true;
ke.key_label = KeyMappingMacOS::remap_key([event keyCode], [event modifierFlags], true);
ke.unicode = 0;
ke.raw = true;
ds->push_to_key_event_buffer(ke);
}
}
}
// MARK: Scroll and pan

View File

@ -36,13 +36,15 @@
class KeyMappingMacOS {
KeyMappingMacOS() {}
static bool is_numpad_key(unsigned int key);
static bool is_numpad_key(unsigned int p_key);
public:
static void initialize();
// Mappings input.
static Key translate_key(unsigned int key);
static unsigned int unmap_key(Key key);
static Key remap_key(unsigned int key, unsigned int state);
static Key translate_key(unsigned int p_key);
static unsigned int unmap_key(Key p_key);
static Key remap_key(unsigned int p_key, unsigned int p_state, bool p_unicode);
// Mapping for menu shortcuts.
static String keycode_get_native_string(Key p_keycode);

View File

@ -33,277 +33,345 @@
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
bool KeyMappingMacOS::is_numpad_key(unsigned int key) {
static const unsigned int table[] = {
0x41, /* kVK_ANSI_KeypadDecimal */
0x43, /* kVK_ANSI_KeypadMultiply */
0x45, /* kVK_ANSI_KeypadPlus */
0x47, /* kVK_ANSI_KeypadClear */
0x4b, /* kVK_ANSI_KeypadDivide */
0x4c, /* kVK_ANSI_KeypadEnter */
0x4e, /* kVK_ANSI_KeypadMinus */
0x51, /* kVK_ANSI_KeypadEquals */
0x52, /* kVK_ANSI_Keypad0 */
0x53, /* kVK_ANSI_Keypad1 */
0x54, /* kVK_ANSI_Keypad2 */
0x55, /* kVK_ANSI_Keypad3 */
0x56, /* kVK_ANSI_Keypad4 */
0x57, /* kVK_ANSI_Keypad5 */
0x58, /* kVK_ANSI_Keypad6 */
0x59, /* kVK_ANSI_Keypad7 */
0x5b, /* kVK_ANSI_Keypad8 */
0x5c, /* kVK_ANSI_Keypad9 */
0x5f, /* kVK_JIS_KeypadComma */
0x00
};
for (int i = 0; table[i] != 0; i++) {
if (key == table[i]) {
return true;
}
}
return false;
}
#include "core/templates/hash_map.h"
#include "core/templates/hash_set.h"
// Keyboard symbol translation table.
static const Key _macos_to_godot_table[128] = {
/* 00 */ Key::A,
/* 01 */ Key::S,
/* 02 */ Key::D,
/* 03 */ Key::F,
/* 04 */ Key::H,
/* 05 */ Key::G,
/* 06 */ Key::Z,
/* 07 */ Key::X,
/* 08 */ Key::C,
/* 09 */ Key::V,
/* 0a */ Key::SECTION, /* ISO Section */
/* 0b */ Key::B,
/* 0c */ Key::Q,
/* 0d */ Key::W,
/* 0e */ Key::E,
/* 0f */ Key::R,
/* 10 */ Key::Y,
/* 11 */ Key::T,
/* 12 */ Key::KEY_1,
/* 13 */ Key::KEY_2,
/* 14 */ Key::KEY_3,
/* 15 */ Key::KEY_4,
/* 16 */ Key::KEY_6,
/* 17 */ Key::KEY_5,
/* 18 */ Key::EQUAL,
/* 19 */ Key::KEY_9,
/* 1a */ Key::KEY_7,
/* 1b */ Key::MINUS,
/* 1c */ Key::KEY_8,
/* 1d */ Key::KEY_0,
/* 1e */ Key::BRACERIGHT,
/* 1f */ Key::O,
/* 20 */ Key::U,
/* 21 */ Key::BRACELEFT,
/* 22 */ Key::I,
/* 23 */ Key::P,
/* 24 */ Key::ENTER,
/* 25 */ Key::L,
/* 26 */ Key::J,
/* 27 */ Key::APOSTROPHE,
/* 28 */ Key::K,
/* 29 */ Key::SEMICOLON,
/* 2a */ Key::BACKSLASH,
/* 2b */ Key::COMMA,
/* 2c */ Key::SLASH,
/* 2d */ Key::N,
/* 2e */ Key::M,
/* 2f */ Key::PERIOD,
/* 30 */ Key::TAB,
/* 31 */ Key::SPACE,
/* 32 */ Key::QUOTELEFT,
/* 33 */ Key::BACKSPACE,
/* 34 */ Key::UNKNOWN,
/* 35 */ Key::ESCAPE,
/* 36 */ Key::META,
/* 37 */ Key::META,
/* 38 */ Key::SHIFT,
/* 39 */ Key::CAPSLOCK,
/* 3a */ Key::ALT,
/* 3b */ Key::CTRL,
/* 3c */ Key::SHIFT,
/* 3d */ Key::ALT,
/* 3e */ Key::CTRL,
/* 3f */ Key::UNKNOWN, /* Function */
/* 40 */ Key::F17,
/* 41 */ Key::KP_PERIOD,
/* 42 */ Key::UNKNOWN,
/* 43 */ Key::KP_MULTIPLY,
/* 44 */ Key::UNKNOWN,
/* 45 */ Key::KP_ADD,
/* 46 */ Key::UNKNOWN,
/* 47 */ Key::NUMLOCK, /* Really KeypadClear... */
/* 48 */ Key::VOLUMEUP, /* VolumeUp */
/* 49 */ Key::VOLUMEDOWN, /* VolumeDown */
/* 4a */ Key::VOLUMEMUTE, /* Mute */
/* 4b */ Key::KP_DIVIDE,
/* 4c */ Key::KP_ENTER,
/* 4d */ Key::UNKNOWN,
/* 4e */ Key::KP_SUBTRACT,
/* 4f */ Key::F18,
/* 50 */ Key::F19,
/* 51 */ Key::EQUAL, /* KeypadEqual */
/* 52 */ Key::KP_0,
/* 53 */ Key::KP_1,
/* 54 */ Key::KP_2,
/* 55 */ Key::KP_3,
/* 56 */ Key::KP_4,
/* 57 */ Key::KP_5,
/* 58 */ Key::KP_6,
/* 59 */ Key::KP_7,
/* 5a */ Key::F20,
/* 5b */ Key::KP_8,
/* 5c */ Key::KP_9,
/* 5d */ Key::YEN, /* JIS Yen */
/* 5e */ Key::UNDERSCORE, /* JIS Underscore */
/* 5f */ Key::COMMA, /* JIS KeypadComma */
/* 60 */ Key::F5,
/* 61 */ Key::F6,
/* 62 */ Key::F7,
/* 63 */ Key::F3,
/* 64 */ Key::F8,
/* 65 */ Key::F9,
/* 66 */ Key::UNKNOWN, /* JIS Eisu */
/* 67 */ Key::F11,
/* 68 */ Key::UNKNOWN, /* JIS Kana */
/* 69 */ Key::F13,
/* 6a */ Key::F16,
/* 6b */ Key::F14,
/* 6c */ Key::UNKNOWN,
/* 6d */ Key::F10,
/* 6e */ Key::MENU,
/* 6f */ Key::F12,
/* 70 */ Key::UNKNOWN,
/* 71 */ Key::F15,
/* 72 */ Key::INSERT, /* Really Help... */
/* 73 */ Key::HOME,
/* 74 */ Key::PAGEUP,
/* 75 */ Key::KEY_DELETE,
/* 76 */ Key::F4,
/* 77 */ Key::END,
/* 78 */ Key::F2,
/* 79 */ Key::PAGEDOWN,
/* 7a */ Key::F1,
/* 7b */ Key::LEFT,
/* 7c */ Key::RIGHT,
/* 7d */ Key::DOWN,
/* 7e */ Key::UP,
/* 7f */ Key::UNKNOWN,
struct HashMapHasherKeys {
static _FORCE_INLINE_ uint32_t hash(const Key p_key) { return hash_fmix32(static_cast<uint32_t>(p_key)); }
static _FORCE_INLINE_ uint32_t hash(const char32_t p_uchar) { return hash_fmix32(p_uchar); }
static _FORCE_INLINE_ uint32_t hash(const unsigned p_key) { return hash_fmix32(p_key); }
};
// Translates a OS X keycode to a Godot keycode.
Key KeyMappingMacOS::translate_key(unsigned int key) {
if (key >= 128) {
return Key::UNKNOWN;
HashSet<unsigned int> numpad_keys;
HashMap<unsigned int, Key, HashMapHasherKeys> keysym_map;
HashMap<Key, unsigned int, HashMapHasherKeys> keysym_map_inv;
HashMap<Key, char32_t, HashMapHasherKeys> keycode_map;
void KeyMappingMacOS::initialize() {
numpad_keys.insert(0x41); //kVK_ANSI_KeypadDecimal
numpad_keys.insert(0x43); //kVK_ANSI_KeypadMultiply
numpad_keys.insert(0x45); //kVK_ANSI_KeypadPlus
numpad_keys.insert(0x47); //kVK_ANSI_KeypadClear
numpad_keys.insert(0x4b); //kVK_ANSI_KeypadDivide
numpad_keys.insert(0x4c); //kVK_ANSI_KeypadEnter
numpad_keys.insert(0x4e); //kVK_ANSI_KeypadMinus
numpad_keys.insert(0x51); //kVK_ANSI_KeypadEquals
numpad_keys.insert(0x52); //kVK_ANSI_Keypad0
numpad_keys.insert(0x53); //kVK_ANSI_Keypad1
numpad_keys.insert(0x54); //kVK_ANSI_Keypad2
numpad_keys.insert(0x55); //kVK_ANSI_Keypad3
numpad_keys.insert(0x56); //kVK_ANSI_Keypad4
numpad_keys.insert(0x57); //kVK_ANSI_Keypad5
numpad_keys.insert(0x58); //kVK_ANSI_Keypad6
numpad_keys.insert(0x59); //kVK_ANSI_Keypad7
numpad_keys.insert(0x5b); //kVK_ANSI_Keypad8
numpad_keys.insert(0x5c); //kVK_ANSI_Keypad9
numpad_keys.insert(0x5f); //kVK_JIS_KeypadComma
keysym_map[0x00] = Key::A;
keysym_map[0x01] = Key::S;
keysym_map[0x02] = Key::D;
keysym_map[0x03] = Key::F;
keysym_map[0x04] = Key::H;
keysym_map[0x05] = Key::G;
keysym_map[0x06] = Key::Z;
keysym_map[0x07] = Key::X;
keysym_map[0x08] = Key::C;
keysym_map[0x09] = Key::V;
keysym_map[0x0a] = Key::SECTION;
keysym_map[0x0b] = Key::B;
keysym_map[0x0c] = Key::Q;
keysym_map[0x0d] = Key::W;
keysym_map[0x0e] = Key::E;
keysym_map[0x0f] = Key::R;
keysym_map[0x10] = Key::Y;
keysym_map[0x11] = Key::T;
keysym_map[0x12] = Key::KEY_1;
keysym_map[0x13] = Key::KEY_2;
keysym_map[0x14] = Key::KEY_3;
keysym_map[0x15] = Key::KEY_4;
keysym_map[0x16] = Key::KEY_6;
keysym_map[0x17] = Key::KEY_5;
keysym_map[0x18] = Key::EQUAL;
keysym_map[0x19] = Key::KEY_9;
keysym_map[0x1a] = Key::KEY_7;
keysym_map[0x1b] = Key::MINUS;
keysym_map[0x1c] = Key::KEY_8;
keysym_map[0x1d] = Key::KEY_0;
keysym_map[0x1e] = Key::BRACERIGHT;
keysym_map[0x1f] = Key::O;
keysym_map[0x20] = Key::U;
keysym_map[0x21] = Key::BRACELEFT;
keysym_map[0x22] = Key::I;
keysym_map[0x23] = Key::P;
keysym_map[0x24] = Key::ENTER;
keysym_map[0x25] = Key::L;
keysym_map[0x26] = Key::J;
keysym_map[0x27] = Key::APOSTROPHE;
keysym_map[0x28] = Key::K;
keysym_map[0x29] = Key::SEMICOLON;
keysym_map[0x2a] = Key::BACKSLASH;
keysym_map[0x2b] = Key::COMMA;
keysym_map[0x2c] = Key::SLASH;
keysym_map[0x2d] = Key::N;
keysym_map[0x2e] = Key::M;
keysym_map[0x2f] = Key::PERIOD;
keysym_map[0x30] = Key::TAB;
keysym_map[0x31] = Key::SPACE;
keysym_map[0x32] = Key::QUOTELEFT;
keysym_map[0x33] = Key::BACKSPACE;
keysym_map[0x35] = Key::ESCAPE;
keysym_map[0x36] = Key::META;
keysym_map[0x37] = Key::META;
keysym_map[0x38] = Key::SHIFT;
keysym_map[0x39] = Key::CAPSLOCK;
keysym_map[0x3a] = Key::ALT;
keysym_map[0x3b] = Key::CTRL;
keysym_map[0x3c] = Key::SHIFT;
keysym_map[0x3d] = Key::ALT;
keysym_map[0x3e] = Key::CTRL;
keysym_map[0x40] = Key::F17;
keysym_map[0x41] = Key::KP_PERIOD;
keysym_map[0x43] = Key::KP_MULTIPLY;
keysym_map[0x45] = Key::KP_ADD;
keysym_map[0x47] = Key::NUMLOCK;
keysym_map[0x48] = Key::VOLUMEUP;
keysym_map[0x49] = Key::VOLUMEDOWN;
keysym_map[0x4a] = Key::VOLUMEMUTE;
keysym_map[0x4b] = Key::KP_DIVIDE;
keysym_map[0x4c] = Key::KP_ENTER;
keysym_map[0x4e] = Key::KP_SUBTRACT;
keysym_map[0x4f] = Key::F18;
keysym_map[0x50] = Key::F19;
keysym_map[0x51] = Key::EQUAL;
keysym_map[0x52] = Key::KP_0;
keysym_map[0x53] = Key::KP_1;
keysym_map[0x54] = Key::KP_2;
keysym_map[0x55] = Key::KP_3;
keysym_map[0x56] = Key::KP_4;
keysym_map[0x57] = Key::KP_5;
keysym_map[0x58] = Key::KP_6;
keysym_map[0x59] = Key::KP_7;
keysym_map[0x5a] = Key::F20;
keysym_map[0x5b] = Key::KP_8;
keysym_map[0x5c] = Key::KP_9;
keysym_map[0x5d] = Key::YEN;
keysym_map[0x5e] = Key::UNDERSCORE;
keysym_map[0x5f] = Key::COMMA;
keysym_map[0x60] = Key::F5;
keysym_map[0x61] = Key::F6;
keysym_map[0x62] = Key::F7;
keysym_map[0x63] = Key::F3;
keysym_map[0x64] = Key::F8;
keysym_map[0x65] = Key::F9;
keysym_map[0x66] = Key::JIS_EISU;
keysym_map[0x67] = Key::F11;
keysym_map[0x68] = Key::JIS_KANA;
keysym_map[0x69] = Key::F13;
keysym_map[0x6a] = Key::F16;
keysym_map[0x6b] = Key::F14;
keysym_map[0x6d] = Key::F10;
keysym_map[0x6e] = Key::MENU;
keysym_map[0x6f] = Key::F12;
keysym_map[0x71] = Key::F15;
keysym_map[0x72] = Key::INSERT;
keysym_map[0x73] = Key::HOME;
keysym_map[0x74] = Key::PAGEUP;
keysym_map[0x75] = Key::KEY_DELETE;
keysym_map[0x76] = Key::F4;
keysym_map[0x77] = Key::END;
keysym_map[0x78] = Key::F2;
keysym_map[0x79] = Key::PAGEDOWN;
keysym_map[0x7a] = Key::F1;
keysym_map[0x7b] = Key::LEFT;
keysym_map[0x7c] = Key::RIGHT;
keysym_map[0x7d] = Key::DOWN;
keysym_map[0x7e] = Key::UP;
for (const KeyValue<unsigned int, Key> &E : keysym_map) {
keysym_map_inv[E.value] = E.key;
}
return _macos_to_godot_table[key];
keycode_map[Key::ESCAPE] = 0x001B;
keycode_map[Key::TAB] = 0x0009;
keycode_map[Key::BACKTAB] = 0x007F;
keycode_map[Key::BACKSPACE] = 0x0008;
keycode_map[Key::ENTER] = 0x000D;
keycode_map[Key::INSERT] = NSInsertFunctionKey;
keycode_map[Key::KEY_DELETE] = 0x007F;
keycode_map[Key::PAUSE] = NSPauseFunctionKey;
keycode_map[Key::PRINT] = NSPrintScreenFunctionKey;
keycode_map[Key::SYSREQ] = NSSysReqFunctionKey;
keycode_map[Key::CLEAR] = NSClearLineFunctionKey;
keycode_map[Key::HOME] = 0x2196;
keycode_map[Key::END] = 0x2198;
keycode_map[Key::LEFT] = 0x001C;
keycode_map[Key::UP] = 0x001E;
keycode_map[Key::RIGHT] = 0x001D;
keycode_map[Key::DOWN] = 0x001F;
keycode_map[Key::PAGEUP] = 0x21DE;
keycode_map[Key::PAGEDOWN] = 0x21DF;
keycode_map[Key::NUMLOCK] = NSClearLineFunctionKey;
keycode_map[Key::SCROLLLOCK] = NSScrollLockFunctionKey;
keycode_map[Key::F1] = NSF1FunctionKey;
keycode_map[Key::F2] = NSF2FunctionKey;
keycode_map[Key::F3] = NSF3FunctionKey;
keycode_map[Key::F4] = NSF4FunctionKey;
keycode_map[Key::F5] = NSF5FunctionKey;
keycode_map[Key::F6] = NSF6FunctionKey;
keycode_map[Key::F7] = NSF7FunctionKey;
keycode_map[Key::F8] = NSF8FunctionKey;
keycode_map[Key::F9] = NSF9FunctionKey;
keycode_map[Key::F10] = NSF10FunctionKey;
keycode_map[Key::F11] = NSF11FunctionKey;
keycode_map[Key::F12] = NSF12FunctionKey;
keycode_map[Key::F13] = NSF13FunctionKey;
keycode_map[Key::F14] = NSF14FunctionKey;
keycode_map[Key::F15] = NSF15FunctionKey;
keycode_map[Key::F16] = NSF16FunctionKey;
keycode_map[Key::F17] = NSF17FunctionKey;
keycode_map[Key::F18] = NSF18FunctionKey;
keycode_map[Key::F19] = NSF19FunctionKey;
keycode_map[Key::F20] = NSF20FunctionKey;
keycode_map[Key::F21] = NSF21FunctionKey;
keycode_map[Key::F22] = NSF22FunctionKey;
keycode_map[Key::F23] = NSF23FunctionKey;
keycode_map[Key::F24] = NSF24FunctionKey;
keycode_map[Key::F25] = NSF25FunctionKey;
keycode_map[Key::F26] = NSF26FunctionKey;
keycode_map[Key::F27] = NSF27FunctionKey;
keycode_map[Key::F28] = NSF28FunctionKey;
keycode_map[Key::F29] = NSF29FunctionKey;
keycode_map[Key::F30] = NSF30FunctionKey;
keycode_map[Key::F31] = NSF31FunctionKey;
keycode_map[Key::F32] = NSF32FunctionKey;
keycode_map[Key::F33] = NSF33FunctionKey;
keycode_map[Key::F34] = NSF34FunctionKey;
keycode_map[Key::F35] = NSF35FunctionKey;
keycode_map[Key::MENU] = NSMenuFunctionKey;
keycode_map[Key::HELP] = NSHelpFunctionKey;
keycode_map[Key::STOP] = NSStopFunctionKey;
keycode_map[Key::LAUNCH0] = NSUserFunctionKey;
keycode_map[Key::SPACE] = 0x0020;
keycode_map[Key::EXCLAM] = '!';
keycode_map[Key::QUOTEDBL] = '\"';
keycode_map[Key::NUMBERSIGN] = '#';
keycode_map[Key::DOLLAR] = '$';
keycode_map[Key::PERCENT] = '\%';
keycode_map[Key::AMPERSAND] = '&';
keycode_map[Key::APOSTROPHE] = '\'';
keycode_map[Key::PARENLEFT] = '(';
keycode_map[Key::PARENRIGHT] = ')';
keycode_map[Key::ASTERISK] = '*';
keycode_map[Key::PLUS] = '+';
keycode_map[Key::COMMA] = ',';
keycode_map[Key::MINUS] = '-';
keycode_map[Key::PERIOD] = '.';
keycode_map[Key::SLASH] = '/';
keycode_map[Key::KEY_0] = '0';
keycode_map[Key::KEY_1] = '1';
keycode_map[Key::KEY_2] = '2';
keycode_map[Key::KEY_3] = '3';
keycode_map[Key::KEY_4] = '4';
keycode_map[Key::KEY_5] = '5';
keycode_map[Key::KEY_6] = '6';
keycode_map[Key::KEY_7] = '7';
keycode_map[Key::KEY_8] = '8';
keycode_map[Key::KEY_9] = '9';
keycode_map[Key::COLON] = ':';
keycode_map[Key::SEMICOLON] = ';';
keycode_map[Key::LESS] = '<';
keycode_map[Key::EQUAL] = '=';
keycode_map[Key::GREATER] = '>';
keycode_map[Key::QUESTION] = '?';
keycode_map[Key::AT] = '@';
keycode_map[Key::A] = 'a';
keycode_map[Key::B] = 'b';
keycode_map[Key::C] = 'c';
keycode_map[Key::D] = 'd';
keycode_map[Key::E] = 'e';
keycode_map[Key::F] = 'f';
keycode_map[Key::G] = 'g';
keycode_map[Key::H] = 'h';
keycode_map[Key::I] = 'i';
keycode_map[Key::J] = 'j';
keycode_map[Key::K] = 'k';
keycode_map[Key::L] = 'l';
keycode_map[Key::M] = 'm';
keycode_map[Key::N] = 'n';
keycode_map[Key::O] = 'o';
keycode_map[Key::P] = 'p';
keycode_map[Key::Q] = 'q';
keycode_map[Key::R] = 'r';
keycode_map[Key::S] = 's';
keycode_map[Key::T] = 't';
keycode_map[Key::U] = 'u';
keycode_map[Key::V] = 'v';
keycode_map[Key::W] = 'w';
keycode_map[Key::X] = 'x';
keycode_map[Key::Y] = 'y';
keycode_map[Key::Z] = 'z';
keycode_map[Key::BRACKETLEFT] = '[';
keycode_map[Key::BACKSLASH] = '\\';
keycode_map[Key::BRACKETRIGHT] = ']';
keycode_map[Key::ASCIICIRCUM] = '^';
keycode_map[Key::UNDERSCORE] = '_';
keycode_map[Key::QUOTELEFT] = '`';
keycode_map[Key::BRACELEFT] = '{';
keycode_map[Key::BAR] = '|';
keycode_map[Key::BRACERIGHT] = '}';
keycode_map[Key::ASCIITILDE] = '~';
}
bool KeyMappingMacOS::is_numpad_key(unsigned int p_key) {
return numpad_keys.has(p_key);
}
// Translates a OS X keycode to a Godot keycode.
Key KeyMappingMacOS::translate_key(unsigned int p_key) {
const Key *key = keysym_map.getptr(p_key);
if (key) {
return *key;
}
return Key::NONE;
}
// Translates a Godot keycode back to a macOS keycode.
unsigned int KeyMappingMacOS::unmap_key(Key key) {
for (int i = 0; i <= 126; i++) {
if (_macos_to_godot_table[i] == key) {
return i;
}
unsigned int KeyMappingMacOS::unmap_key(Key p_key) {
const unsigned int *key = keysym_map_inv.getptr(p_key);
if (key) {
return *key;
}
return 127;
}
struct _KeyCodeMap {
UniChar kchar;
Key kcode;
};
static const _KeyCodeMap _keycodes[55] = {
{ '`', Key::QUOTELEFT },
{ '~', Key::ASCIITILDE },
{ '0', Key::KEY_0 },
{ '1', Key::KEY_1 },
{ '2', Key::KEY_2 },
{ '3', Key::KEY_3 },
{ '4', Key::KEY_4 },
{ '5', Key::KEY_5 },
{ '6', Key::KEY_6 },
{ '7', Key::KEY_7 },
{ '8', Key::KEY_8 },
{ '9', Key::KEY_9 },
{ '-', Key::MINUS },
{ '_', Key::UNDERSCORE },
{ '=', Key::EQUAL },
{ '+', Key::PLUS },
{ 'q', Key::Q },
{ 'w', Key::W },
{ 'e', Key::E },
{ 'r', Key::R },
{ 't', Key::T },
{ 'y', Key::Y },
{ 'u', Key::U },
{ 'i', Key::I },
{ 'o', Key::O },
{ 'p', Key::P },
{ '[', Key::BRACELEFT },
{ ']', Key::BRACERIGHT },
{ '{', Key::BRACELEFT },
{ '}', Key::BRACERIGHT },
{ 'a', Key::A },
{ 's', Key::S },
{ 'd', Key::D },
{ 'f', Key::F },
{ 'g', Key::G },
{ 'h', Key::H },
{ 'j', Key::J },
{ 'k', Key::K },
{ 'l', Key::L },
{ ';', Key::SEMICOLON },
{ ':', Key::COLON },
{ '\'', Key::APOSTROPHE },
{ '\"', Key::QUOTEDBL },
{ '\\', Key::BACKSLASH },
{ '#', Key::NUMBERSIGN },
{ 'z', Key::Z },
{ 'x', Key::X },
{ 'c', Key::C },
{ 'v', Key::V },
{ 'b', Key::B },
{ 'n', Key::N },
{ 'm', Key::M },
{ ',', Key::COMMA },
{ '.', Key::PERIOD },
{ '/', Key::SLASH }
};
// Remap key according to current keyboard layout.
Key KeyMappingMacOS::remap_key(unsigned int key, unsigned int state) {
if (is_numpad_key(key)) {
return translate_key(key);
Key KeyMappingMacOS::remap_key(unsigned int p_key, unsigned int p_state, bool p_unicode) {
if (is_numpad_key(p_key)) {
return translate_key(p_key);
}
TISInputSourceRef current_keyboard = TISCopyCurrentKeyboardInputSource();
if (!current_keyboard) {
return translate_key(key);
return translate_key(p_key);
}
CFDataRef layout_data = (CFDataRef)TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData);
if (!layout_data) {
return translate_key(key);
return translate_key(p_key);
}
const UCKeyboardLayout *keyboard_layout = (const UCKeyboardLayout *)CFDataGetBytePtr(layout_data);
String keysym;
UInt32 keys_down = 0;
UniChar chars[4];
UniCharCount real_length;
UniChar chars[256] = {};
UniCharCount real_length = 0;
OSStatus err = UCKeyTranslate(keyboard_layout,
key,
p_key,
kUCKeyActionDisplay,
(state >> 8) & 0xFF,
(p_unicode) ? 0 : (p_state >> 8) & 0xFF,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&keys_down,
@ -312,165 +380,26 @@ Key KeyMappingMacOS::remap_key(unsigned int key, unsigned int state) {
chars);
if (err != noErr) {
return translate_key(key);
return translate_key(p_key);
}
for (unsigned int i = 0; i < 55; i++) {
if (_keycodes[i].kchar == chars[0]) {
return _keycodes[i].kcode;
keysym = String::utf16((char16_t *)chars, real_length);
if (keysym.is_empty()) {
return translate_key(p_key);
}
char32_t c = keysym[0];
if (p_unicode) {
return fix_key_label(c, translate_key(p_key));
} else {
return fix_keycode(c, translate_key(p_key));
}
return translate_key(key);
}
struct _KeyCodeText {
Key code;
char32_t text;
};
static const _KeyCodeText _native_keycodes[] = {
/* clang-format off */
{Key::ESCAPE ,0x001B},
{Key::TAB ,0x0009},
{Key::BACKTAB ,0x007F},
{Key::BACKSPACE ,0x0008},
{Key::ENTER ,0x000D},
{Key::INSERT ,NSInsertFunctionKey},
{Key::KEY_DELETE ,0x007F},
{Key::PAUSE ,NSPauseFunctionKey},
{Key::PRINT ,NSPrintScreenFunctionKey},
{Key::SYSREQ ,NSSysReqFunctionKey},
{Key::CLEAR ,NSClearLineFunctionKey},
{Key::HOME ,0x2196},
{Key::END ,0x2198},
{Key::LEFT ,0x001C},
{Key::UP ,0x001E},
{Key::RIGHT ,0x001D},
{Key::DOWN ,0x001F},
{Key::PAGEUP ,0x21DE},
{Key::PAGEDOWN ,0x21DF},
{Key::NUMLOCK ,NSClearLineFunctionKey},
{Key::SCROLLLOCK ,NSScrollLockFunctionKey},
{Key::F1 ,NSF1FunctionKey},
{Key::F2 ,NSF2FunctionKey},
{Key::F3 ,NSF3FunctionKey},
{Key::F4 ,NSF4FunctionKey},
{Key::F5 ,NSF5FunctionKey},
{Key::F6 ,NSF6FunctionKey},
{Key::F7 ,NSF7FunctionKey},
{Key::F8 ,NSF8FunctionKey},
{Key::F9 ,NSF9FunctionKey},
{Key::F10 ,NSF10FunctionKey},
{Key::F11 ,NSF11FunctionKey},
{Key::F12 ,NSF12FunctionKey},
{Key::F13 ,NSF13FunctionKey},
{Key::F14 ,NSF14FunctionKey},
{Key::F15 ,NSF15FunctionKey},
{Key::F16 ,NSF16FunctionKey},
{Key::F17 ,NSF17FunctionKey},
{Key::F18 ,NSF18FunctionKey},
{Key::F19 ,NSF19FunctionKey},
{Key::F20 ,NSF20FunctionKey},
{Key::F21 ,NSF21FunctionKey},
{Key::F22 ,NSF22FunctionKey},
{Key::F23 ,NSF23FunctionKey},
{Key::F24 ,NSF24FunctionKey},
{Key::F25 ,NSF25FunctionKey},
{Key::F26 ,NSF26FunctionKey},
{Key::F27 ,NSF27FunctionKey},
{Key::F28 ,NSF28FunctionKey},
{Key::F29 ,NSF29FunctionKey},
{Key::F30 ,NSF30FunctionKey},
{Key::F31 ,NSF31FunctionKey},
{Key::F32 ,NSF32FunctionKey},
{Key::F33 ,NSF33FunctionKey},
{Key::F34 ,NSF34FunctionKey},
{Key::F35 ,NSF35FunctionKey},
{Key::MENU ,NSMenuFunctionKey},
{Key::HELP ,NSHelpFunctionKey},
{Key::STOP ,NSStopFunctionKey},
{Key::LAUNCH0 ,NSUserFunctionKey},
{Key::SPACE ,0x0020},
{Key::EXCLAM ,'!'},
{Key::QUOTEDBL ,'\"'},
{Key::NUMBERSIGN ,'#'},
{Key::DOLLAR ,'$'},
{Key::PERCENT ,'\%'},
{Key::AMPERSAND ,'&'},
{Key::APOSTROPHE ,'\''},
{Key::PARENLEFT ,'('},
{Key::PARENRIGHT ,')'},
{Key::ASTERISK ,'*'},
{Key::PLUS ,'+'},
{Key::COMMA ,','},
{Key::MINUS ,'-'},
{Key::PERIOD ,'.'},
{Key::SLASH ,'/'},
{Key::KEY_0 ,'0'},
{Key::KEY_1 ,'1'},
{Key::KEY_2 ,'2'},
{Key::KEY_3 ,'3'},
{Key::KEY_4 ,'4'},
{Key::KEY_5 ,'5'},
{Key::KEY_6 ,'6'},
{Key::KEY_7 ,'7'},
{Key::KEY_8 ,'8'},
{Key::KEY_9 ,'9'},
{Key::COLON ,':'},
{Key::SEMICOLON ,';'},
{Key::LESS ,'<'},
{Key::EQUAL ,'='},
{Key::GREATER ,'>'},
{Key::QUESTION ,'?'},
{Key::AT ,'@'},
{Key::A ,'a'},
{Key::B ,'b'},
{Key::C ,'c'},
{Key::D ,'d'},
{Key::E ,'e'},
{Key::F ,'f'},
{Key::G ,'g'},
{Key::H ,'h'},
{Key::I ,'i'},
{Key::J ,'j'},
{Key::K ,'k'},
{Key::L ,'l'},
{Key::M ,'m'},
{Key::N ,'n'},
{Key::O ,'o'},
{Key::P ,'p'},
{Key::Q ,'q'},
{Key::R ,'r'},
{Key::S ,'s'},
{Key::T ,'t'},
{Key::U ,'u'},
{Key::V ,'v'},
{Key::W ,'w'},
{Key::X ,'x'},
{Key::Y ,'y'},
{Key::Z ,'z'},
{Key::BRACKETLEFT ,'['},
{Key::BACKSLASH ,'\\'},
{Key::BRACKETRIGHT ,']'},
{Key::ASCIICIRCUM ,'^'},
{Key::UNDERSCORE ,'_'},
{Key::QUOTELEFT ,'`'},
{Key::BRACELEFT ,'{'},
{Key::BAR ,'|'},
{Key::BRACERIGHT ,'}'},
{Key::ASCIITILDE ,'~'},
{Key::NONE ,0x0000}
/* clang-format on */
};
String KeyMappingMacOS::keycode_get_native_string(Key p_keycode) {
const _KeyCodeText *kct = &_native_keycodes[0];
while (kct->text) {
if (kct->code == p_keycode) {
return String::chr(kct->text);
}
kct++;
const char32_t *key = keycode_map.getptr(p_keycode);
if (key) {
return String::chr(*key);
}
return String();
}

View File

@ -121,18 +121,25 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers
// Resume audio context after input in case autoplay was denied.
OS_Web::get_singleton()->resume_audio();
char32_t c = 0x00;
String unicode = String::utf8(key_event.key);
if (unicode.length() == 1) {
c = unicode[0];
}
Key keycode = dom_code2godot_scancode(key_event.code, key_event.key, false);
Key scancode = dom_code2godot_scancode(key_event.code, key_event.key, true);
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_echo(p_repeat);
ev->set_keycode(dom_code2godot_scancode(key_event.code, key_event.key, false));
ev->set_physical_keycode(dom_code2godot_scancode(key_event.code, key_event.key, true));
ev->set_keycode(fix_keycode(c, keycode));
ev->set_physical_keycode(scancode);
ev->set_key_label(fix_key_label(c, keycode));
ev->set_unicode(fix_unicode(c));
ev->set_pressed(p_pressed);
dom2godot_mod(ev, p_modifiers);
String unicode = String::utf8(key_event.key);
if (unicode.length() == 1) {
ev->set_unicode(unicode[0]);
}
Input::get_singleton()->parse_input_event(ev);
// Make sure to flush all events so we can call restricted APIs inside the event.

View File

@ -33,7 +33,7 @@
// See https://w3c.github.io/uievents-code/#code-value-tables
Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], bool p_physical) {
#define DOM2GODOT(p_str, p_godot_code) \
if (memcmp((const void *)p_str, (void *)p_code, strlen(p_str) + 1) == 0) { \
if (memcmp((const void *)p_str, (void *)(p_physical ? p_key : p_code), strlen(p_str) + 1) == 0) { \
return Key::p_godot_code; \
}
@ -70,35 +70,6 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("NumpadStar", KP_MULTIPLY); // or ASTERISK ?
DOM2GODOT("NumpadSubtract", KP_SUBTRACT);
// Printable ASCII.
if (!p_physical) {
uint8_t b0 = (uint8_t)p_key[0];
uint8_t b1 = (uint8_t)p_key[1];
uint8_t b2 = (uint8_t)p_key[2];
if (b1 == 0 && b0 > 0x1F && b0 < 0x7F) { // ASCII.
if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII.
b0 -= 32;
}
return (Key)b0;
}
#define _U_2BYTES_MASK 0xE0
#define _U_2BYTES 0xC0
// Latin-1 codes.
if (b2 == 0 && (b0 & _U_2BYTES_MASK) == _U_2BYTES) { // 2-bytes utf8, only known latin.
uint32_t key = ((b0 & ~_U_2BYTES_MASK) << 6) | (b1 & 0x3F);
if (key >= 0xA0 && key <= 0xDF) {
return (Key)key;
}
if (key >= 0xE0 && key <= 0xFF) { // Lowercase known latin.
key -= 0x20;
return (Key)key;
}
}
#undef _U_2BYTES_MASK
#undef _U_2BYTES
}
// Alphanumeric section.
DOM2GODOT("Backquote", QUOTELEFT);
DOM2GODOT("Backslash", BACKSLASH);
@ -162,8 +133,8 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("ControlLeft", CTRL);
DOM2GODOT("ControlRight", CTRL);
DOM2GODOT("Enter", ENTER);
DOM2GODOT("MetaLeft", SUPER_L);
DOM2GODOT("MetaRight", SUPER_R);
DOM2GODOT("MetaLeft", META);
DOM2GODOT("MetaRight", META);
DOM2GODOT("ShiftLeft", SHIFT);
DOM2GODOT("ShiftRight", SHIFT);
DOM2GODOT("Space", SPACE);
@ -227,6 +198,21 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b
DOM2GODOT("AudioVolumeMute", VOLUMEMUTE);
DOM2GODOT("AudioVolumeUp", VOLUMEUP);
//DOM2GODOT("WakeUp", UNKNOWN);
return Key::UNKNOWN;
// Printable ASCII.
uint8_t b0 = (uint8_t)p_key[0];
uint8_t b1 = (uint8_t)p_key[1];
if (b0 >= 0x20 && b0 < 0x7F) { // ASCII.
if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII.
b0 -= 32;
}
return (Key)b0;
} else if (b0 == 0xC2 && b1 == 0xA5) {
return Key::YEN;
} else if (b0 == 0xC2 && b1 == 0xA7) {
return Key::SECTION;
}
return Key::NONE;
#undef DOM2GODOT
}

View File

@ -1610,6 +1610,58 @@ bool DisplayServerWindows::can_any_window_draw() const {
return false;
}
Vector2i DisplayServerWindows::ime_get_selection() const {
_THREAD_SAFE_METHOD_
DisplayServer::WindowID window_id = _get_focused_window_or_popup();
const WindowData &wd = windows[window_id];
if (!wd.ime_active) {
return Vector2i();
}
int cursor = ImmGetCompositionStringW(wd.im_himc, GCS_CURSORPOS, nullptr, 0);
int32_t length = ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, nullptr, 0);
wchar_t *string = reinterpret_cast<wchar_t *>(memalloc(length));
ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, string, length);
int32_t utf32_cursor = 0;
for (int32_t i = 0; i < length / sizeof(wchar_t); i++) {
if ((string[i] & 0xfffffc00) == 0xd800) {
i++;
}
if (i < cursor) {
utf32_cursor++;
} else {
break;
}
}
memdelete(string);
return Vector2i(utf32_cursor, 0);
}
String DisplayServerWindows::ime_get_text() const {
_THREAD_SAFE_METHOD_
DisplayServer::WindowID window_id = _get_focused_window_or_popup();
const WindowData &wd = windows[window_id];
if (!wd.ime_active) {
return String();
}
String ret;
int32_t length = ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, nullptr, 0);
wchar_t *string = reinterpret_cast<wchar_t *>(memalloc(length));
ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, string, length);
ret.parse_utf16((char16_t *)string, length / sizeof(wchar_t));
memdelete(string);
return ret;
}
void DisplayServerWindows::window_set_ime_active(const bool p_active, WindowID p_window) {
_THREAD_SAFE_METHOD_
@ -1617,11 +1669,12 @@ void DisplayServerWindows::window_set_ime_active(const bool p_active, WindowID p
WindowData &wd = windows[p_window];
if (p_active) {
wd.ime_active = true;
ImmAssociateContext(wd.hWnd, wd.im_himc);
window_set_ime_position(wd.im_position, p_window);
} else {
ImmAssociateContext(wd.hWnd, (HIMC)0);
wd.ime_active = false;
}
}
@ -1639,7 +1692,7 @@ void DisplayServerWindows::window_set_ime_position(const Point2i &p_pos, WindowI
}
COMPOSITIONFORM cps;
cps.dwStyle = CFS_FORCE_POSITION;
cps.dwStyle = CFS_POINT;
cps.ptCurrentPos.x = wd.im_position.x;
cps.ptCurrentPos.y = wd.im_position.y;
ImmSetCompositionWindow(himc, &cps);
@ -3353,10 +3406,18 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
windows[window_id].focus_timer_id = 0U;
}
} break;
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYUP:
if (windows[window_id].ime_suppress_next_keyup) {
windows[window_id].ime_suppress_next_keyup = false;
break;
}
[[fallthrough]];
case WM_SYSKEYDOWN:
case WM_KEYDOWN: {
if (windows[window_id].ime_in_progress) {
break;
}
if (wParam == VK_SHIFT) {
shift_mem = (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN);
}
@ -3379,6 +3440,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
[[fallthrough]];
}
case WM_CHAR: {
if (windows[window_id].ime_in_progress) {
break;
}
ERR_BREAK(key_event_pos >= KEY_EVENT_BUFFER_SIZE);
// Make sure we don't include modifiers for the modifier key itself.
@ -3402,9 +3466,43 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
key_event_buffer[key_event_pos++] = ke;
} break;
case WM_IME_COMPOSITION: {
CANDIDATEFORM cf;
cf.dwIndex = 0;
cf.dwStyle = CFS_EXCLUDE;
cf.ptCurrentPos.x = windows[window_id].im_position.x;
cf.ptCurrentPos.y = windows[window_id].im_position.y;
cf.rcArea.left = windows[window_id].im_position.x;
cf.rcArea.right = windows[window_id].im_position.x;
cf.rcArea.top = windows[window_id].im_position.y;
cf.rcArea.bottom = windows[window_id].im_position.y;
ImmSetCandidateWindow(windows[window_id].im_himc, &cf);
if (windows[window_id].ime_active) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
} break;
case WM_INPUTLANGCHANGEREQUEST: {
// FIXME: Do something?
} break;
case WM_IME_STARTCOMPOSITION: {
if (windows[window_id].ime_active) {
windows[window_id].ime_in_progress = true;
if (key_event_pos > 0) {
key_event_pos--;
}
}
return 0;
} break;
case WM_IME_ENDCOMPOSITION: {
if (windows[window_id].ime_active) {
windows[window_id].ime_in_progress = false;
windows[window_id].ime_suppress_next_keyup = true;
}
return 0;
} break;
case WM_IME_NOTIFY: {
return 0;
} break;
case WM_TOUCH: {
BOOL bHandled = FALSE;
UINT cInputs = LOWORD(wParam);
@ -3557,24 +3655,36 @@ void DisplayServerWindows::_process_key_events() {
Ref<InputEventKey> k;
k.instantiate();
Key keycode = KeyMappingWindows::get_keysym(MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK));
Key key_label = keycode;
Key physical_keycode = KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24));
static BYTE keyboard_state[256];
memset(keyboard_state, 0, 256);
wchar_t chars[256] = {};
UINT extended_code = MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK_EX);
if (!(ke.lParam & (1 << 24)) && ToUnicodeEx(extended_code, (ke.lParam >> 16) & 0xFF, keyboard_state, chars, 255, 0, GetKeyboardLayout(0)) > 0) {
String keysym = String::utf16((char16_t *)chars, 255);
if (!keysym.is_empty()) {
key_label = fix_key_label(keysym[0], keycode);
}
}
k->set_window_id(ke.window_id);
k->set_shift_pressed(ke.shift);
k->set_alt_pressed(ke.alt);
k->set_ctrl_pressed(ke.control);
k->set_meta_pressed(ke.meta);
k->set_pressed(true);
k->set_keycode((Key)KeyMappingWindows::get_keysym(MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK)));
k->set_physical_keycode((Key)(KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24))));
k->set_unicode(unicode);
k->set_keycode(keycode);
k->set_physical_keycode(physical_keycode);
k->set_key_label(key_label);
k->set_unicode(fix_unicode(unicode));
if (k->get_unicode() && gr_mem) {
k->set_alt_pressed(false);
k->set_ctrl_pressed(false);
}
if (k->get_unicode() < 32) {
k->set_unicode(0);
}
Input::get_singleton()->parse_input_event(k);
} else {
// Do nothing.
@ -3593,14 +3703,28 @@ void DisplayServerWindows::_process_key_events() {
k->set_pressed(ke.uMsg == WM_KEYDOWN);
Key keycode = KeyMappingWindows::get_keysym(ke.wParam);
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
// Special case for Numpad Enter key.
k->set_keycode(Key::KP_ENTER);
} else {
k->set_keycode((Key)KeyMappingWindows::get_keysym(ke.wParam));
keycode = Key::KP_ENTER;
}
Key key_label = keycode;
Key physical_keycode = KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24));
static BYTE keyboard_state[256];
memset(keyboard_state, 0, 256);
wchar_t chars[256] = {};
UINT extended_code = MapVirtualKey((ke.lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK_EX);
if (!(ke.lParam & (1 << 24)) && ToUnicodeEx(extended_code, (ke.lParam >> 16) & 0xFF, keyboard_state, chars, 255, 0, GetKeyboardLayout(0)) > 0) {
String keysym = String::utf16((char16_t *)chars, 255);
if (!keysym.is_empty()) {
key_label = fix_key_label(keysym[0], keycode);
}
}
k->set_physical_keycode((Key)(KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24))));
k->set_keycode(keycode);
k->set_physical_keycode(physical_keycode);
k->set_key_label(key_label);
if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) {
char32_t unicode = key_event_buffer[i + 1].wParam;
@ -3621,17 +3745,13 @@ void DisplayServerWindows::_process_key_events() {
} else {
prev_wck = 0;
}
k->set_unicode(unicode);
k->set_unicode(fix_unicode(unicode));
}
if (k->get_unicode() && gr_mem) {
k->set_alt_pressed(false);
k->set_ctrl_pressed(false);
}
if (k->get_unicode() < 32) {
k->set_unicode(0);
}
k->set_echo((ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30))));
Input::get_singleton()->parse_input_event(k);
@ -3842,7 +3962,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
// IME.
wd.im_himc = ImmGetContext(wd.hWnd);
ImmReleaseContext(wd.hWnd, wd.im_himc);
ImmAssociateContext(wd.hWnd, (HIMC)0);
wd.im_position = Vector2();
@ -3936,6 +4056,8 @@ void DisplayServerWindows::tablet_set_current_driver(const String &p_driver) {
}
DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
KeyMappingWindows::initialize();
drop_events = false;
key_event_pos = 0;
@ -4043,7 +4165,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
wc.lpszClassName = L"Engine";
if (!RegisterClassExW(&wc)) {
MessageBox(nullptr, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
MessageBoxW(nullptr, L"Failed To Register The Window Class.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
r_error = ERR_UNAVAILABLE;
return;
}
@ -4122,7 +4244,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
// from making the system unresponsive.
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
DWORD index = 0;
HANDLE handle = AvSetMmThreadCharacteristics("Games", &index);
HANDLE handle = AvSetMmThreadCharacteristicsW(L"Games", &index);
if (handle) {
AvSetMmThreadPriority(handle, AVRT_PRIORITY_CRITICAL);
}

View File

@ -405,6 +405,9 @@ class DisplayServerWindows : public DisplayServer {
// IME
HIMC im_himc;
Vector2 im_position;
bool ime_active = false;
bool ime_in_progress = false;
bool ime_suppress_next_keyup = false;
bool layered_window = false;
@ -592,6 +595,9 @@ public:
virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID) override;
virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID) override;
virtual Point2i ime_get_selection() const override;
virtual String ime_get_text() const override;
virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;

View File

@ -30,490 +30,386 @@
#include "key_mapping_windows.h"
#include <stdio.h>
#include "core/templates/hash_map.h"
// This provides translation from Windows virtual key codes to Godot and back.
// See WinUser.h and the below for documentation:
// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
struct _WinTranslatePair {
Key keysym;
unsigned int keycode;
struct HashMapHasherKeys {
static _FORCE_INLINE_ uint32_t hash(const Key p_key) { return hash_fmix32(static_cast<uint32_t>(p_key)); }
static _FORCE_INLINE_ uint32_t hash(const char32_t p_uchar) { return hash_fmix32(p_uchar); }
static _FORCE_INLINE_ uint32_t hash(const unsigned p_key) { return hash_fmix32(p_key); }
};
static _WinTranslatePair _vk_to_keycode[] = {
HashMap<unsigned int, Key, HashMapHasherKeys> vk_map;
HashMap<unsigned int, Key, HashMapHasherKeys> scansym_map;
HashMap<Key, unsigned int, HashMapHasherKeys> scansym_map_inv;
HashMap<unsigned int, Key, HashMapHasherKeys> scansym_map_ext;
void KeyMappingWindows::initialize() {
// VK_LBUTTON (0x01)
// VK_RBUTTON (0x02)
// VK_CANCEL (0x03)
// VK_MBUTTON (0x04)
// VK_XBUTTON1 (0x05)
// VK_XBUTTON2 (0x06)
// We have no mappings for the above, as we only map keyboard buttons here.
// VK_XBUTTON2 (0x06), We have no mappings for the above;as we only map keyboard buttons here.
// 0x07 is undefined.
{ Key::BACKSPACE, VK_BACK }, // (0x08)
{ Key::TAB, VK_TAB }, // (0x09)
vk_map[VK_BACK] = Key::BACKSPACE; // (0x08)
vk_map[VK_TAB] = Key::TAB; // (0x09)
// 0x0A-0B are reserved.
{ Key::CLEAR, VK_CLEAR }, // (0x0C)
{ Key::ENTER, VK_RETURN }, // (0x0D)
vk_map[VK_CLEAR] = Key::CLEAR; // (0x0C)
vk_map[VK_RETURN] = Key::ENTER; // (0x0D)
// 0x0E-0F are undefined.
{ Key::SHIFT, VK_SHIFT }, // (0x10)
{ Key::CTRL, VK_CONTROL }, // (0x11)
{ Key::ALT, VK_MENU }, // (0x12)
{ Key::PAUSE, VK_PAUSE }, // (0x13)
{ Key::CAPSLOCK, VK_CAPITAL }, // (0x14)
// 0x15-1A are IME keys. We have no mapping.
{ Key::ESCAPE, VK_ESCAPE }, // (0x1B)
// 0x1C-1F are IME keys. We have no mapping.
{ Key::SPACE, VK_SPACE }, // (0x20)
{ Key::PAGEUP, VK_PRIOR }, // (0x21)
{ Key::PAGEDOWN, VK_NEXT }, // (0x22)
{ Key::END, VK_END }, // (0x23)
{ Key::HOME, VK_HOME }, // (0x24)
{ Key::LEFT, VK_LEFT }, // (0x25)
{ Key::UP, VK_UP }, // (0x26)
{ Key::RIGHT, VK_RIGHT }, // (0x27)
{ Key::DOWN, VK_DOWN }, // (0x28)
// VK_SELECT (0x29)
// Old select key, e.g. on Digital Equipment Corporation keyboards.
// Old and uncommon, we have no mapping.
{ Key::PRINT, VK_PRINT }, // (0x2A)
// Old IBM key, modern keyboards use VK_SNAPSHOT. Map to VK_SNAPSHOT.
// VK_EXECUTE (0x2B)
// Old and uncommon, we have no mapping.
{ Key::PRINT, VK_SNAPSHOT }, // (0x2C)
{ Key::INSERT, VK_INSERT }, // (0x2D)
{ Key::KEY_DELETE, VK_DELETE }, // (0x2E)
{ Key::HELP, VK_HELP }, // (0x2F)
// Old and uncommon, but we have a mapping.
{ Key::KEY_0, (0x30) }, // 0 key.
{ Key::KEY_1, (0x31) }, // 1 key.
{ Key::KEY_2, (0x32) }, // 2 key.
{ Key::KEY_3, (0x33) }, // 3 key.
{ Key::KEY_4, (0x34) }, // 4 key.
{ Key::KEY_5, (0x35) }, // 5 key.
{ Key::KEY_6, (0x36) }, // 6 key.
{ Key::KEY_7, (0x37) }, // 7 key.
{ Key::KEY_8, (0x38) }, // 8 key.
{ Key::KEY_9, (0x39) }, // 9 key.
vk_map[VK_SHIFT] = Key::SHIFT; // (0x10)
vk_map[VK_CONTROL] = Key::CTRL; // (0x11)
vk_map[VK_MENU] = Key::ALT; // (0x12)
vk_map[VK_PAUSE] = Key::PAUSE; // (0x13)
vk_map[VK_CAPITAL] = Key::CAPSLOCK; // (0x14)
// 0x15-1A are IME keys.
vk_map[VK_ESCAPE] = Key::ESCAPE; // (0x1B)
// 0x1C-1F are IME keys.
vk_map[VK_SPACE] = Key::SPACE; // (0x20)
vk_map[VK_PRIOR] = Key::PAGEUP; // (0x21)
vk_map[VK_NEXT] = Key::PAGEDOWN; // (0x22)
vk_map[VK_END] = Key::END; // (0x23)
vk_map[VK_HOME] = Key::HOME; // (0x24)
vk_map[VK_LEFT] = Key::LEFT; // (0x25)
vk_map[VK_UP] = Key::UP; // (0x26)
vk_map[VK_RIGHT] = Key::RIGHT; // (0x27)
vk_map[VK_DOWN] = Key::DOWN; // (0x28)
// VK_SELECT (0x29), Old select key; e.g. on Digital Equipment Corporation keyboards.
vk_map[VK_PRINT] = Key::PRINT; // (0x2A), Old IBM key; modern keyboards use VK_SNAPSHOT.
// VK_EXECUTE (0x2B), Old and uncommon.
vk_map[VK_SNAPSHOT] = Key::PRINT; // (0x2C)
vk_map[VK_INSERT] = Key::INSERT; // (0x2D)
vk_map[VK_DELETE] = Key::KEY_DELETE; // (0x2E)
vk_map[VK_HELP] = Key::HELP; // (0x2F)
vk_map[0x30] = Key::KEY_0; // 0 key.
vk_map[0x31] = Key::KEY_1; // 1 key.
vk_map[0x32] = Key::KEY_2; // 2 key.
vk_map[0x33] = Key::KEY_3; // 3 key.
vk_map[0x34] = Key::KEY_4; // 4 key.
vk_map[0x35] = Key::KEY_5; // 5 key.
vk_map[0x36] = Key::KEY_6; // 6 key.
vk_map[0x37] = Key::KEY_7; // 7 key.
vk_map[0x38] = Key::KEY_8; // 8 key.
vk_map[0x39] = Key::KEY_9; // 9 key.
// 0x3A-40 are undefined.
{ Key::A, (0x41) }, // A key.
{ Key::B, (0x42) }, // B key.
{ Key::C, (0x43) }, // C key.
{ Key::D, (0x44) }, // D key.
{ Key::E, (0x45) }, // E key.
{ Key::F, (0x46) }, // F key.
{ Key::G, (0x47) }, // G key.
{ Key::H, (0x48) }, // H key.
{ Key::I, (0x49) }, // I key
{ Key::J, (0x4A) }, // J key.
{ Key::K, (0x4B) }, // K key.
{ Key::L, (0x4C) }, // L key.
{ Key::M, (0x4D) }, // M key.
{ Key::N, (0x4E) }, // N key.
{ Key::O, (0x4F) }, // O key.
{ Key::P, (0x50) }, // P key.
{ Key::Q, (0x51) }, // Q key.
{ Key::R, (0x52) }, // R key.
{ Key::S, (0x53) }, // S key.
{ Key::T, (0x54) }, // T key.
{ Key::U, (0x55) }, // U key.
{ Key::V, (0x56) }, // V key.
{ Key::W, (0x57) }, // W key.
{ Key::X, (0x58) }, // X key.
{ Key::Y, (0x59) }, // Y key.
{ Key::Z, (0x5A) }, // Z key.
{ (Key)KeyModifierMask::META, VK_LWIN }, // (0x5B)
{ (Key)KeyModifierMask::META, VK_RWIN }, // (0x5C)
{ Key::MENU, VK_APPS }, // (0x5D)
vk_map[0x41] = Key::A; // A key.
vk_map[0x42] = Key::B; // B key.
vk_map[0x43] = Key::C; // C key.
vk_map[0x44] = Key::D; // D key.
vk_map[0x45] = Key::E; // E key.
vk_map[0x46] = Key::F; // F key.
vk_map[0x47] = Key::G; // G key.
vk_map[0x48] = Key::H; // H key.
vk_map[0x49] = Key::I; // I key
vk_map[0x4A] = Key::J; // J key.
vk_map[0x4B] = Key::K; // K key.
vk_map[0x4C] = Key::L; // L key.
vk_map[0x4D] = Key::M; // M key.
vk_map[0x4E] = Key::N; // N key.
vk_map[0x4F] = Key::O; // O key.
vk_map[0x50] = Key::P; // P key.
vk_map[0x51] = Key::Q; // Q key.
vk_map[0x52] = Key::R; // R key.
vk_map[0x53] = Key::S; // S key.
vk_map[0x54] = Key::T; // T key.
vk_map[0x55] = Key::U; // U key.
vk_map[0x56] = Key::V; // V key.
vk_map[0x57] = Key::W; // W key.
vk_map[0x58] = Key::X; // X key.
vk_map[0x59] = Key::Y; // Y key.
vk_map[0x5A] = Key::Z; // Z key.
vk_map[VK_LWIN] = (Key)Key::META; // (0x5B)
vk_map[VK_RWIN] = (Key)Key::META; // (0x5C)
vk_map[VK_APPS] = Key::MENU; // (0x5D)
// 0x5E is reserved.
{ Key::STANDBY, VK_SLEEP }, // (0x5F)
{ Key::KP_0, VK_NUMPAD0 }, // (0x60)
{ Key::KP_1, VK_NUMPAD1 }, // (0x61)
{ Key::KP_2, VK_NUMPAD2 }, // (0x62)
{ Key::KP_3, VK_NUMPAD3 }, // (0x63)
{ Key::KP_4, VK_NUMPAD4 }, // (0x64)
{ Key::KP_5, VK_NUMPAD5 }, // (0x65)
{ Key::KP_6, VK_NUMPAD6 }, // (0x66)
{ Key::KP_7, VK_NUMPAD7 }, // (0x67)
{ Key::KP_8, VK_NUMPAD8 }, // (0x68)
{ Key::KP_9, VK_NUMPAD9 }, // (0x69)
{ Key::KP_MULTIPLY, VK_MULTIPLY }, // (0x6A)
{ Key::KP_ADD, VK_ADD }, // (0x6B)
{ Key::KP_PERIOD, VK_SEPARATOR }, // (0x6C)
// VK_SEPERATOR (key 0x6C) is not found on US keyboards.
// It is used on some Brazilian and Far East keyboards.
// We don't have a direct mapping, map to period.
{ Key::KP_SUBTRACT, VK_SUBTRACT }, // (0x6D)
{ Key::KP_PERIOD, VK_DECIMAL }, // (0x6E)
{ Key::KP_DIVIDE, VK_DIVIDE }, // (0x6F)
{ Key::F1, VK_F1 }, // (0x70)
{ Key::F2, VK_F2 }, // (0x71)
{ Key::F3, VK_F3 }, // (0x72)
{ Key::F4, VK_F4 }, // (0x73)
{ Key::F5, VK_F5 }, // (0x74)
{ Key::F6, VK_F6 }, // (0x75)
{ Key::F7, VK_F7 }, // (0x76)
{ Key::F8, VK_F8 }, // (0x77)
{ Key::F9, VK_F9 }, // (0x78)
{ Key::F10, VK_F10 }, // (0x79)
{ Key::F11, VK_F11 }, // (0x7A)
{ Key::F12, VK_F12 }, // (0x7B)
{ Key::F13, VK_F13 }, // (0x7C)
{ Key::F14, VK_F14 }, // (0x7D)
{ Key::F15, VK_F15 }, // (0x7E)
{ Key::F16, VK_F16 }, // (0x7F)
{ Key::F17, VK_F17 }, // (0x80)
{ Key::F18, VK_F18 }, // (0x81)
{ Key::F19, VK_F19 }, // (0x82)
{ Key::F20, VK_F20 }, // (0x83)
{ Key::F21, VK_F21 }, // (0x84)
{ Key::F22, VK_F22 }, // (0x85)
{ Key::F23, VK_F23 }, // (0x86)
{ Key::F24, VK_F24 }, // (0x87)
vk_map[VK_SLEEP] = Key::STANDBY; // (0x5F)
vk_map[VK_NUMPAD0] = Key::KP_0; // (0x60)
vk_map[VK_NUMPAD1] = Key::KP_1; // (0x61)
vk_map[VK_NUMPAD2] = Key::KP_2; // (0x62)
vk_map[VK_NUMPAD3] = Key::KP_3; // (0x63)
vk_map[VK_NUMPAD4] = Key::KP_4; // (0x64)
vk_map[VK_NUMPAD5] = Key::KP_5; // (0x65)
vk_map[VK_NUMPAD6] = Key::KP_6; // (0x66)
vk_map[VK_NUMPAD7] = Key::KP_7; // (0x67)
vk_map[VK_NUMPAD8] = Key::KP_8; // (0x68)
vk_map[VK_NUMPAD9] = Key::KP_9; // (0x69)
vk_map[VK_MULTIPLY] = Key::KP_MULTIPLY; // (0x6A)
vk_map[VK_ADD] = Key::KP_ADD; // (0x6B)
vk_map[VK_SEPARATOR] = Key::KP_PERIOD; // (0x6C)
vk_map[VK_SUBTRACT] = Key::KP_SUBTRACT; // (0x6D)
vk_map[VK_DECIMAL] = Key::KP_PERIOD; // (0x6E)
vk_map[VK_DIVIDE] = Key::KP_DIVIDE; // (0x6F)
vk_map[VK_F1] = Key::F1; // (0x70)
vk_map[VK_F2] = Key::F2; // (0x71)
vk_map[VK_F3] = Key::F3; // (0x72)
vk_map[VK_F4] = Key::F4; // (0x73)
vk_map[VK_F5] = Key::F5; // (0x74)
vk_map[VK_F6] = Key::F6; // (0x75)
vk_map[VK_F7] = Key::F7; // (0x76)
vk_map[VK_F8] = Key::F8; // (0x77)
vk_map[VK_F9] = Key::F9; // (0x78)
vk_map[VK_F10] = Key::F10; // (0x79)
vk_map[VK_F11] = Key::F11; // (0x7A)
vk_map[VK_F12] = Key::F12; // (0x7B)
vk_map[VK_F13] = Key::F13; // (0x7C)
vk_map[VK_F14] = Key::F14; // (0x7D)
vk_map[VK_F15] = Key::F15; // (0x7E)
vk_map[VK_F16] = Key::F16; // (0x7F)
vk_map[VK_F17] = Key::F17; // (0x80)
vk_map[VK_F18] = Key::F18; // (0x81)
vk_map[VK_F19] = Key::F19; // (0x82)
vk_map[VK_F20] = Key::F20; // (0x83)
vk_map[VK_F21] = Key::F21; // (0x84)
vk_map[VK_F22] = Key::F22; // (0x85)
vk_map[VK_F23] = Key::F23; // (0x86)
vk_map[VK_F24] = Key::F24; // (0x87)
// 0x88-8F are reserved for UI navigation.
{ Key::NUMLOCK, VK_NUMLOCK }, // (0x90)
{ Key::SCROLLLOCK, VK_SCROLL }, // (0x91)
{ Key::EQUAL, VK_OEM_NEC_EQUAL }, // (0x92)
// OEM NEC PC-9800 numpad '=' key.
// 0x93-96 are OEM specific (e.g. used by Fujitsu/OASYS), we have no mappings.
vk_map[VK_NUMLOCK] = Key::NUMLOCK; // (0x90)
vk_map[VK_SCROLL] = Key::SCROLLLOCK; // (0x91)
vk_map[VK_OEM_NEC_EQUAL] = Key::EQUAL; // (0x92), OEM NEC PC-9800 numpad '=' key.
// 0x93-96 are OEM specific (e.g. used by Fujitsu/OASYS);
// 0x97-9F are unassigned.
{ Key::SHIFT, VK_LSHIFT }, // (0xA0)
{ Key::SHIFT, VK_RSHIFT }, // (0xA1)
{ Key::CTRL, VK_LCONTROL }, // (0xA2)
{ Key::CTRL, VK_RCONTROL }, // (0xA3)
{ Key::MENU, VK_LMENU }, // (0xA4)
{ Key::MENU, VK_RMENU }, // (0xA5)
{ Key::BACK, VK_BROWSER_BACK }, // (0xA6)
{ Key::FORWARD, VK_BROWSER_FORWARD }, // (0xA7)
{ Key::REFRESH, VK_BROWSER_REFRESH }, // (0xA8)
{ Key::STOP, VK_BROWSER_STOP }, // (0xA9)
{ Key::SEARCH, VK_BROWSER_SEARCH }, // (0xAA)
{ Key::FAVORITES, VK_BROWSER_FAVORITES }, // (0xAB)
{ Key::HOMEPAGE, VK_BROWSER_HOME }, // (0xAC)
{ Key::VOLUMEMUTE, VK_VOLUME_MUTE }, // (0xAD)
{ Key::VOLUMEDOWN, VK_VOLUME_DOWN }, // (0xAE)
{ Key::VOLUMEUP, VK_VOLUME_UP }, // (0xAF)
{ Key::MEDIANEXT, VK_MEDIA_NEXT_TRACK }, // (0xB0)
{ Key::MEDIAPREVIOUS, VK_MEDIA_PREV_TRACK }, // (0xB1)
{ Key::MEDIASTOP, VK_MEDIA_STOP }, // (0xB2)
{ Key::MEDIAPLAY, VK_MEDIA_PLAY_PAUSE }, // (0xB3)
// Media button play/pause toggle.
// Map to media play (there is no other 'play' mapping on Windows).
{ Key::LAUNCHMAIL, VK_LAUNCH_MAIL }, // (0xB4)
{ Key::LAUNCHMEDIA, VK_LAUNCH_MEDIA_SELECT }, // (0xB5)
{ Key::LAUNCH0, VK_LAUNCH_APP1 }, // (0xB6)
{ Key::LAUNCH1, VK_LAUNCH_APP2 }, // (0xB7)
vk_map[VK_LSHIFT] = Key::SHIFT; // (0xA0)
vk_map[VK_RSHIFT] = Key::SHIFT; // (0xA1)
vk_map[VK_LCONTROL] = Key::CTRL; // (0xA2)
vk_map[VK_RCONTROL] = Key::CTRL; // (0xA3)
vk_map[VK_LMENU] = Key::MENU; // (0xA4)
vk_map[VK_RMENU] = Key::MENU; // (0xA5)
vk_map[VK_BROWSER_BACK] = Key::BACK; // (0xA6)
vk_map[VK_BROWSER_FORWARD] = Key::FORWARD; // (0xA7)
vk_map[VK_BROWSER_REFRESH] = Key::REFRESH; // (0xA8)
vk_map[VK_BROWSER_STOP] = Key::STOP; // (0xA9)
vk_map[VK_BROWSER_SEARCH] = Key::SEARCH; // (0xAA)
vk_map[VK_BROWSER_FAVORITES] = Key::FAVORITES; // (0xAB)
vk_map[VK_BROWSER_HOME] = Key::HOMEPAGE; // (0xAC)
vk_map[VK_VOLUME_MUTE] = Key::VOLUMEMUTE; // (0xAD)
vk_map[VK_VOLUME_DOWN] = Key::VOLUMEDOWN; // (0xAE)
vk_map[VK_VOLUME_UP] = Key::VOLUMEUP; // (0xAF)
vk_map[VK_MEDIA_NEXT_TRACK] = Key::MEDIANEXT; // (0xB0)
vk_map[VK_MEDIA_PREV_TRACK] = Key::MEDIAPREVIOUS; // (0xB1)
vk_map[VK_MEDIA_STOP] = Key::MEDIASTOP; // (0xB2)
vk_map[VK_MEDIA_PLAY_PAUSE] = Key::MEDIAPLAY; // (0xB3), Media button play/pause toggle.
vk_map[VK_LAUNCH_MAIL] = Key::LAUNCHMAIL; // (0xB4)
vk_map[VK_LAUNCH_MEDIA_SELECT] = Key::LAUNCHMEDIA; // (0xB5)
vk_map[VK_LAUNCH_APP1] = Key::LAUNCH0; // (0xB6)
vk_map[VK_LAUNCH_APP2] = Key::LAUNCH1; // (0xB7)
// 0xB8-B9 are reserved.
{ Key::SEMICOLON, VK_OEM_1 }, // (0xBA)
// Misc. character, can vary by keyboard/region.
// Windows 2000/XP: For US standard keyboards, the ';:' key.
{ Key::EQUAL, VK_OEM_PLUS }, // (0xBB)
// Windows 2000/XP: For any country/region, the '+' key.
{ Key::COMMA, VK_OEM_COMMA }, // (0xBC)
// Windows 2000/XP: For any country/region, the ',' key.
{ Key::MINUS, VK_OEM_MINUS }, // (0xBD)
// Windows 2000/XP: For any country/region, the '-' key.
{ Key::PERIOD, VK_OEM_PERIOD }, // (0xBE)
// Windows 2000/XP: For any country/region, the '.' key.
{ Key::SLASH, VK_OEM_2 }, // (0xBF)
// Windows 2000/XP: For US standard keyboards, the '/?' key.
{ Key::QUOTELEFT, VK_OEM_3 }, // (0xC0)
// Windows 2000/XP: For US standard keyboards, the '`~' key.
vk_map[VK_OEM_1] = Key::SEMICOLON; // (0xBA), Misc. character;can vary by keyboard/region. For US standard keyboards;the ';:' key.
vk_map[VK_OEM_PLUS] = Key::EQUAL; // (0xBB)
vk_map[VK_OEM_COMMA] = Key::COMMA; // (0xBC)
vk_map[VK_OEM_MINUS] = Key::MINUS; // (0xBD)
vk_map[VK_OEM_PERIOD] = Key::PERIOD; // (0xBE)
vk_map[VK_OEM_2] = Key::SLASH; // (0xBF), For US standard keyboards;the '/?' key.
vk_map[VK_OEM_3] = Key::QUOTELEFT; // (0xC0), For US standard keyboards;the '`~' key.
// 0xC1-D7 are reserved. 0xD8-DA are unassigned.
// TODO: 0xC3-DA may be used for old gamepads? Maybe we want to support this? See WinUser.h.
{ Key::BRACKETLEFT, VK_OEM_4 }, // (0xDB)
// Misc. character, can vary by keyboard/region.
// Windows 2000/XP: For US standard keyboards, the '[{' key.
{ Key::BACKSLASH, VK_OEM_5 }, // (0xDC)
// Misc. character, can vary by keyboard/region.
// Windows 2000/XP: For US standard keyboards, the '\|' key.
{ Key::BRACKETRIGHT, VK_OEM_6 }, // (0xDD)
// Misc. character, can vary by keyboard/region.
// Windows 2000/XP: For US standard keyboards, the ']}' key.
{ Key::APOSTROPHE, VK_OEM_7 }, // (0xDE)
// Misc. character, can vary by keyboard/region.
// Windows 2000/XP: For US standard keyboards, single quote/double quote.
// 0xC3-DA may be used for old gamepads? Maybe we want to support this? See WinUser.h.
vk_map[VK_OEM_4] = Key::BRACKETLEFT; // (0xDB), For US standard keyboards;the '[{' key.
vk_map[VK_OEM_5] = Key::BACKSLASH; // (0xDC), For US standard keyboards;the '\|' key.
vk_map[VK_OEM_6] = Key::BRACKETRIGHT; // (0xDD), For US standard keyboards;the ']}' key.
vk_map[VK_OEM_7] = Key::APOSTROPHE; // (0xDE), For US standard keyboards;single quote/double quote.
// VK_OEM_8 (0xDF)
// Misc. character, can vary by keyboard/region. We have no mapping.
// 0xE0 is reserved. 0xE1 is OEM specific.
vk_map[VK_OEM_102] = Key::BAR; // (0xE2), Either angle bracket or backslash key on the RT 102-key keyboard.
vk_map[VK_ICO_HELP] = Key::HELP; // (0xE3)
// 0xE4 is OEM (e.g. ICO) specific.
// VK_PROCESSKEY (0xE5), For IME.
vk_map[VK_ICO_CLEAR] = Key::CLEAR; // (0xE6)
// VK_PACKET (0xE7), Used to pass Unicode characters as if they were keystrokes.
// 0xE8 is unassigned.
// 0xE9-F5 are OEM (Nokia/Ericsson) specific.
vk_map[VK_ATTN] = Key::ESCAPE; // (0xF6), Old IBM 'ATTN' key used on midrange computers ;e.g. AS/400.
vk_map[VK_CRSEL] = Key::TAB; // (0xF7), Old IBM 3270 'CrSel' (cursor select) key; used to select data fields.
// VK_EXSEL (0xF7), Old IBM 3270 extended selection key.
// VK_EREOF (0xF8), Old IBM 3270 erase to end of field key.
vk_map[VK_PLAY] = Key::MEDIAPLAY; // (0xFA), Old IBM 3270 'Play' key.
// VK_ZOOM (0xFB), Old IBM 3290 'Zoom' key.
// VK_NONAME (0xFC), Reserved.
// VK_PA1 (0xFD), Old IBM 3270 PA1 key.
vk_map[VK_OEM_CLEAR] = Key::CLEAR; // (0xFE), OEM specific clear key. Unclear how it differs from normal clear.
// 0xE0 is reserved. 0xE1 is OEM specific, we have no mapping.
scansym_map[0x00] = Key::PAUSE;
scansym_map[0x01] = Key::ESCAPE;
scansym_map[0x02] = Key::KEY_1;
scansym_map[0x03] = Key::KEY_2;
scansym_map[0x04] = Key::KEY_3;
scansym_map[0x05] = Key::KEY_4;
scansym_map[0x06] = Key::KEY_5;
scansym_map[0x07] = Key::KEY_6;
scansym_map[0x08] = Key::KEY_7;
scansym_map[0x09] = Key::KEY_8;
scansym_map[0x0A] = Key::KEY_9;
scansym_map[0x0B] = Key::KEY_0;
scansym_map[0x0C] = Key::MINUS;
scansym_map[0x0D] = Key::EQUAL;
scansym_map[0x0E] = Key::BACKSPACE;
scansym_map[0x0F] = Key::TAB;
scansym_map[0x10] = Key::Q;
scansym_map[0x11] = Key::W;
scansym_map[0x12] = Key::E;
scansym_map[0x13] = Key::R;
scansym_map[0x14] = Key::T;
scansym_map[0x15] = Key::Y;
scansym_map[0x16] = Key::U;
scansym_map[0x17] = Key::I;
scansym_map[0x18] = Key::O;
scansym_map[0x19] = Key::P;
scansym_map[0x1A] = Key::BRACELEFT;
scansym_map[0x1B] = Key::BRACERIGHT;
scansym_map[0x1C] = Key::ENTER;
scansym_map[0x1D] = Key::CTRL;
scansym_map[0x1E] = Key::A;
scansym_map[0x1F] = Key::S;
scansym_map[0x20] = Key::D;
scansym_map[0x21] = Key::F;
scansym_map[0x22] = Key::G;
scansym_map[0x23] = Key::H;
scansym_map[0x24] = Key::J;
scansym_map[0x25] = Key::K;
scansym_map[0x26] = Key::L;
scansym_map[0x27] = Key::SEMICOLON;
scansym_map[0x28] = Key::APOSTROPHE;
scansym_map[0x29] = Key::QUOTELEFT;
scansym_map[0x2A] = Key::SHIFT;
scansym_map[0x2B] = Key::BACKSLASH;
scansym_map[0x2C] = Key::Z;
scansym_map[0x2D] = Key::X;
scansym_map[0x2E] = Key::C;
scansym_map[0x2F] = Key::V;
scansym_map[0x30] = Key::B;
scansym_map[0x31] = Key::N;
scansym_map[0x32] = Key::M;
scansym_map[0x33] = Key::COMMA;
scansym_map[0x34] = Key::PERIOD;
scansym_map[0x35] = Key::SLASH;
scansym_map[0x36] = Key::SHIFT;
scansym_map[0x37] = Key::KP_MULTIPLY;
scansym_map[0x38] = Key::ALT;
scansym_map[0x39] = Key::SPACE;
scansym_map[0x3A] = Key::CAPSLOCK;
scansym_map[0x3B] = Key::F1;
scansym_map[0x3C] = Key::F2;
scansym_map[0x3D] = Key::F3;
scansym_map[0x3E] = Key::F4;
scansym_map[0x3F] = Key::F5;
scansym_map[0x40] = Key::F6;
scansym_map[0x41] = Key::F7;
scansym_map[0x42] = Key::F8;
scansym_map[0x43] = Key::F9;
scansym_map[0x44] = Key::F10;
scansym_map[0x45] = Key::NUMLOCK;
scansym_map[0x46] = Key::SCROLLLOCK;
scansym_map[0x47] = Key::KP_7;
scansym_map[0x48] = Key::KP_8;
scansym_map[0x49] = Key::KP_9;
scansym_map[0x4A] = Key::KP_SUBTRACT;
scansym_map[0x4B] = Key::KP_4;
scansym_map[0x4C] = Key::KP_5;
scansym_map[0x4D] = Key::KP_6;
scansym_map[0x4E] = Key::KP_ADD;
scansym_map[0x4F] = Key::KP_1;
scansym_map[0x50] = Key::KP_2;
scansym_map[0x51] = Key::KP_3;
scansym_map[0x52] = Key::KP_0;
scansym_map[0x53] = Key::KP_PERIOD;
scansym_map[0x57] = Key::SECTION;
scansym_map[0x57] = Key::F11;
scansym_map[0x58] = Key::F12;
scansym_map[0x5B] = Key::META;
scansym_map[0x5C] = Key::META;
scansym_map[0x5D] = Key::MENU;
scansym_map[0x64] = Key::F13;
scansym_map[0x65] = Key::F14;
scansym_map[0x66] = Key::F15;
scansym_map[0x67] = Key::F16;
scansym_map[0x68] = Key::F17;
scansym_map[0x69] = Key::F18;
scansym_map[0x6A] = Key::F19;
scansym_map[0x6B] = Key::F20;
scansym_map[0x6C] = Key::F21;
scansym_map[0x6D] = Key::F22;
scansym_map[0x6E] = Key::F23;
// scansym_map[0x71] = Key::JIS_KANA;
// scansym_map[0x72] = Key::JIS_EISU;
scansym_map[0x76] = Key::F24;
// VK_OEM_102 (0xE2)
// Either angle bracket or backslash key on the RT 102-key keyboard.
// Old and uncommon, we have no mapping.
for (const KeyValue<unsigned int, Key> &E : scansym_map) {
scansym_map_inv[E.value] = E.key;
}
{ Key::HELP, VK_ICO_HELP }, // (0xE3)
// OEM (ICO) help key. Map to help.
// 0xE4 is OEM (e.g. ICO) specific, we have no mapping.
// VK_PROCESSKEY (0xE5)
// For IME, we have no mapping.
{ Key::CLEAR, VK_ICO_CLEAR }, // (0xE6)
// OEM (ICO) clear key. Map to clear.
// VK_PACKET (0xE7)
// Used to pass Unicode characters as if they were keystrokes.
// See Win32 API docs. We have no mapping.
// 0xE8 is unassigned, 0xE9-F5 are OEM (Nokia/Ericsson) specific, we have no mappings.
{ Key::ESCAPE, VK_ATTN }, // (0xF6)
// Old IBM 'ATTN' key used on midrange computers, e.g. AS/400, map to Escape.
{ Key::TAB, VK_CRSEL }, // (0xF7)
// Old IBM 3270 'CrSel' (cursor select) key, used to select data fields, map to Tab.
// VK_EXSEL (0xF7)
// Old IBM 3270 extended selection key. No mapping.
// VK_EREOF (0xF8)
// Old IBM 3270 erase to end of field key. No mapping.
{ Key::MEDIAPLAY, VK_PLAY }, // (0xFA)
// Old IBM 3270 'Play' key. Map to media play.
// VK_ZOOM (0xFB)
// Old IBM 3290 'Zoom' key. No mapping.
// VK_NONAME (0xFC)
// Reserved. No mapping.
// VK_PA1 (0xFD)
// Old IBM 3270 PA1 key. No mapping.
{ Key::CLEAR, VK_OEM_CLEAR }, // (0xFE)
// OEM specific clear key. Unclear how it differs from normal clear. Map to clear.
{ Key::UNKNOWN, 0 }
};
static _WinTranslatePair _scancode_to_keycode[] = {
{ Key::ESCAPE, 0x01 },
{ Key::KEY_1, 0x02 },
{ Key::KEY_2, 0x03 },
{ Key::KEY_3, 0x04 },
{ Key::KEY_4, 0x05 },
{ Key::KEY_5, 0x06 },
{ Key::KEY_6, 0x07 },
{ Key::KEY_7, 0x08 },
{ Key::KEY_8, 0x09 },
{ Key::KEY_9, 0x0A },
{ Key::KEY_0, 0x0B },
{ Key::MINUS, 0x0C },
{ Key::EQUAL, 0x0D },
{ Key::BACKSPACE, 0x0E },
{ Key::TAB, 0x0F },
{ Key::Q, 0x10 },
{ Key::W, 0x11 },
{ Key::E, 0x12 },
{ Key::R, 0x13 },
{ Key::T, 0x14 },
{ Key::Y, 0x15 },
{ Key::U, 0x16 },
{ Key::I, 0x17 },
{ Key::O, 0x18 },
{ Key::P, 0x19 },
{ Key::BRACELEFT, 0x1A },
{ Key::BRACERIGHT, 0x1B },
{ Key::ENTER, 0x1C },
{ Key::CTRL, 0x1D },
{ Key::A, 0x1E },
{ Key::S, 0x1F },
{ Key::D, 0x20 },
{ Key::F, 0x21 },
{ Key::G, 0x22 },
{ Key::H, 0x23 },
{ Key::J, 0x24 },
{ Key::K, 0x25 },
{ Key::L, 0x26 },
{ Key::SEMICOLON, 0x27 },
{ Key::APOSTROPHE, 0x28 },
{ Key::QUOTELEFT, 0x29 },
{ Key::SHIFT, 0x2A },
{ Key::BACKSLASH, 0x2B },
{ Key::Z, 0x2C },
{ Key::X, 0x2D },
{ Key::C, 0x2E },
{ Key::V, 0x2F },
{ Key::B, 0x30 },
{ Key::N, 0x31 },
{ Key::M, 0x32 },
{ Key::COMMA, 0x33 },
{ Key::PERIOD, 0x34 },
{ Key::SLASH, 0x35 },
{ Key::SHIFT, 0x36 },
{ Key::PRINT, 0x37 },
{ Key::ALT, 0x38 },
{ Key::SPACE, 0x39 },
{ Key::CAPSLOCK, 0x3A },
{ Key::F1, 0x3B },
{ Key::F2, 0x3C },
{ Key::F3, 0x3D },
{ Key::F4, 0x3E },
{ Key::F5, 0x3F },
{ Key::F6, 0x40 },
{ Key::F7, 0x41 },
{ Key::F8, 0x42 },
{ Key::F9, 0x43 },
{ Key::F10, 0x44 },
{ Key::NUMLOCK, 0x45 },
{ Key::SCROLLLOCK, 0x46 },
{ Key::HOME, 0x47 },
{ Key::UP, 0x48 },
{ Key::PAGEUP, 0x49 },
{ Key::KP_SUBTRACT, 0x4A },
{ Key::LEFT, 0x4B },
{ Key::KP_5, 0x4C },
{ Key::RIGHT, 0x4D },
{ Key::KP_ADD, 0x4E },
{ Key::END, 0x4F },
{ Key::DOWN, 0x50 },
{ Key::PAGEDOWN, 0x51 },
{ Key::INSERT, 0x52 },
{ Key::KEY_DELETE, 0x53 },
{ Key::F11, 0x57 },
{ Key::F12, 0x58 },
{ Key::META, 0x5B },
{ Key::META, 0x5C },
{ Key::MENU, 0x5D },
{ Key::F13, 0x64 },
{ Key::F14, 0x65 },
{ Key::F15, 0x66 },
{ Key::F16, 0x67 },
{ Key::F17, 0x68 },
{ Key::F18, 0x69 },
{ Key::F19, 0x6A },
{ Key::F20, 0x6B },
{ Key::F21, 0x6C },
{ Key::F22, 0x6D },
{ Key::F23, 0x6E },
{ Key::F24, 0x76 },
{ Key::UNKNOWN, 0 }
};
scansym_map_ext[0x09] = Key::MENU;
scansym_map_ext[0x10] = Key::MEDIAPREVIOUS;
scansym_map_ext[0x19] = Key::MEDIANEXT;
scansym_map_ext[0x1C] = Key::KP_ENTER;
scansym_map_ext[0x20] = Key::VOLUMEMUTE;
scansym_map_ext[0x21] = Key::LAUNCH1;
scansym_map_ext[0x22] = Key::MEDIAPLAY;
scansym_map_ext[0x24] = Key::MEDIASTOP;
scansym_map_ext[0x2E] = Key::VOLUMEDOWN;
scansym_map_ext[0x30] = Key::VOLUMEUP;
scansym_map_ext[0x32] = Key::HOMEPAGE;
scansym_map_ext[0x35] = Key::KP_DIVIDE;
scansym_map_ext[0x37] = Key::PRINT;
scansym_map_ext[0x3A] = Key::KP_ADD;
scansym_map_ext[0x45] = Key::NUMLOCK;
scansym_map_ext[0x47] = Key::HOME;
scansym_map_ext[0x48] = Key::UP;
scansym_map_ext[0x49] = Key::PAGEUP;
scansym_map_ext[0x4A] = Key::KP_SUBTRACT;
scansym_map_ext[0x4B] = Key::LEFT;
scansym_map_ext[0x4C] = Key::KP_5;
scansym_map_ext[0x4D] = Key::RIGHT;
scansym_map_ext[0x4E] = Key::KP_ADD;
scansym_map_ext[0x4F] = Key::END;
scansym_map_ext[0x50] = Key::DOWN;
scansym_map_ext[0x51] = Key::PAGEDOWN;
scansym_map_ext[0x52] = Key::INSERT;
scansym_map_ext[0x53] = Key::KEY_DELETE;
scansym_map_ext[0x5D] = Key::MENU;
scansym_map_ext[0x5F] = Key::STANDBY;
scansym_map_ext[0x65] = Key::SEARCH;
scansym_map_ext[0x66] = Key::FAVORITES;
scansym_map_ext[0x67] = Key::REFRESH;
scansym_map_ext[0x68] = Key::STOP;
scansym_map_ext[0x69] = Key::FORWARD;
scansym_map_ext[0x6A] = Key::BACK;
scansym_map_ext[0x6B] = Key::LAUNCH0;
scansym_map_ext[0x6C] = Key::LAUNCHMAIL;
scansym_map_ext[0x6D] = Key::LAUNCHMEDIA;
scansym_map_ext[0x78] = Key::MEDIARECORD;
}
Key KeyMappingWindows::get_keysym(unsigned int p_code) {
for (int i = 0; _vk_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_vk_to_keycode[i].keycode == p_code) {
return _vk_to_keycode[i].keysym;
const Key *key = vk_map.getptr(p_code);
if (key) {
return *key;
}
}
return Key::UNKNOWN;
}
unsigned int KeyMappingWindows::get_scancode(Key p_keycode) {
for (int i = 0; _scancode_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_scancode_to_keycode[i].keysym == p_keycode) {
return _scancode_to_keycode[i].keycode;
const unsigned int *key = scansym_map_inv.getptr(p_keycode);
if (key) {
return *key;
}
}
return 0;
}
Key KeyMappingWindows::get_scansym(unsigned int p_code, bool p_extended) {
Key keycode = Key::UNKNOWN;
for (int i = 0; _scancode_to_keycode[i].keysym != Key::UNKNOWN; i++) {
if (_scancode_to_keycode[i].keycode == p_code) {
keycode = _scancode_to_keycode[i].keysym;
break;
}
}
if (p_extended) {
switch (keycode) {
case Key::ENTER: {
keycode = Key::KP_ENTER;
} break;
case Key::SLASH: {
keycode = Key::KP_DIVIDE;
} break;
case Key::CAPSLOCK: {
keycode = Key::KP_ADD;
} break;
default:
break;
}
} else {
switch (keycode) {
case Key::NUMLOCK: {
keycode = Key::PAUSE;
} break;
case Key::HOME: {
keycode = Key::KP_7;
} break;
case Key::UP: {
keycode = Key::KP_8;
} break;
case Key::PAGEUP: {
keycode = Key::KP_9;
} break;
case Key::LEFT: {
keycode = Key::KP_4;
} break;
case Key::RIGHT: {
keycode = Key::KP_6;
} break;
case Key::END: {
keycode = Key::KP_1;
} break;
case Key::DOWN: {
keycode = Key::KP_2;
} break;
case Key::PAGEDOWN: {
keycode = Key::KP_3;
} break;
case Key::INSERT: {
keycode = Key::KP_0;
} break;
case Key::KEY_DELETE: {
keycode = Key::KP_PERIOD;
} break;
case Key::PRINT: {
keycode = Key::KP_MULTIPLY;
} break;
default:
break;
const Key *key = scansym_map_ext.getptr(p_code);
if (key) {
return *key;
}
}
return keycode;
const Key *key = scansym_map.getptr(p_code);
if (key) {
return *key;
}
return Key::NONE;
}
bool KeyMappingWindows::is_extended_key(unsigned int p_code) {

View File

@ -41,6 +41,8 @@ class KeyMappingWindows {
KeyMappingWindows() {}
public:
static void initialize();
static Key get_keysym(unsigned int p_code);
static unsigned int get_scancode(Key p_keycode);
static Key get_scansym(unsigned int p_code, bool p_extended);

View File

@ -952,9 +952,9 @@ void LineEdit::_notification(int p_what) {
// Prevent carets from disappearing at theme scales below 1.0 (if the caret width is 1).
const int caret_width = theme_cache.caret_width * MAX(1, theme_cache.base_scale);
if (ime_text.length() == 0) {
if (ime_text.is_empty() || ime_selection.y == 0) {
// Normal caret.
CaretInfo caret = TS->shaped_text_get_carets(text_rid, caret_column);
CaretInfo caret = TS->shaped_text_get_carets(text_rid, ime_text.is_empty() ? caret_column : caret_column + ime_selection.x);
if (using_placeholder || (caret.l_caret == Rect2() && caret.t_caret == Rect2())) {
// No carets, add one at the start.
int h = theme_cache.font->get_height(theme_cache.font_size);
@ -980,6 +980,7 @@ void LineEdit::_notification(int p_what) {
}
} break;
}
RenderingServer::get_singleton()->canvas_item_add_rect(ci, caret.l_caret, caret_color);
} else {
if (caret.l_caret != Rect2() && caret.l_dir == TextServer::DIRECTION_AUTO) {
@ -1009,7 +1010,8 @@ void LineEdit::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, caret.t_caret, caret_color);
}
} else {
}
if (!ime_text.is_empty()) {
{
// IME intermediate text range.
Vector<Vector2> sel = TS->shaped_text_get_selection(text_rid, caret_column, caret_column + ime_text.length());
@ -1030,6 +1032,7 @@ void LineEdit::_notification(int p_what) {
}
{
// IME caret.
if (ime_selection.y > 0) {
Vector<Vector2> sel = TS->shaped_text_get_selection(text_rid, caret_column + ime_selection.x, caret_column + ime_selection.x + ime_selection.y);
for (int i = 0; i < sel.size(); i++) {
Rect2 rect = Rect2(sel[i].x + ofs.x, ofs.y, sel[i].y - sel[i].x, text_height);
@ -1048,11 +1051,13 @@ void LineEdit::_notification(int p_what) {
}
}
}
}
if (has_focus()) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + Point2(using_placeholder ? 0 : x_ofs, y_ofs + TS->shaped_text_get_size(text_rid).y), get_viewport()->get_window_id());
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2);
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + pos, get_viewport()->get_window_id());
}
}
} break;
@ -1071,8 +1076,8 @@ void LineEdit::_notification(int p_what) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
Point2 column = Point2(get_caret_column(), 1) * get_minimum_size().height;
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + column, get_viewport()->get_window_id());
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2);
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + pos, get_viewport()->get_window_id());
}
show_virtual_keyboard();
@ -1103,6 +1108,11 @@ void LineEdit::_notification(int p_what) {
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
if (!ime_text.is_empty()) {
selection_delete();
}
_shape();
set_caret_column(caret_column); // Update scroll_offset

View File

@ -1319,11 +1319,12 @@ void TextEdit::_notification(int p_what) {
if (!clipped && get_caret_line(c) == line && carets_wrap_index[c] == line_wrap_index) {
carets.write[c].draw_pos.y = ofs_y + ldata->get_line_descent(line_wrap_index);
if (ime_text.length() == 0) {
if (ime_text.is_empty() || ime_selection.y == 0) {
// Normal caret.
CaretInfo ts_caret;
if (str.length() != 0) {
if (!str.is_empty() || !ime_text.is_empty()) {
// Get carets.
ts_caret = TS->shaped_text_get_carets(rid, get_caret_column(c));
ts_caret = TS->shaped_text_get_carets(rid, ime_text.is_empty() ? get_caret_column(c) : get_caret_column(c) + ime_selection.x);
} else {
// No carets, add one at the start.
int h = font->get_height(font_size);
@ -1426,7 +1427,8 @@ void TextEdit::_notification(int p_what) {
}
}
}
} else {
}
if (!ime_text.is_empty()) {
{
// IME Intermediate text range.
Vector<Vector2> sel = TS->shaped_text_get_selection(rid, get_caret_column(c), get_caret_column(c) + ime_text.length());
@ -1546,6 +1548,10 @@ void TextEdit::_notification(int p_what) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
if (!ime_text.is_empty()) {
delete_selection();
}
for (int i = 0; i < carets.size(); i++) {
String t;
if (get_caret_column(i) >= 0) {

View File

@ -106,11 +106,11 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
// Key is None without a physical key.
none_key.set_keycode(Key::NONE);
CHECK(none_key.as_text() == " (Physical)");
CHECK(none_key.as_text() == "(Unset)");
// Key is none and has modifiers.
none_key.set_ctrl_pressed(true);
CHECK(none_key.as_text() == "Ctrl+ (Physical)");
CHECK(none_key.as_text() == "Ctrl+(Unset)");
// Key is None WITH a physical key AND modifiers.
none_key.set_physical_keycode(Key::ENTER);
@ -144,8 +144,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") {
InputEventKey none_key;
// Set physical to true.
CHECK(none_key.to_string() == "InputEventKey: keycode=0 (), mods=none, physical=true, pressed=false, echo=false");
CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, 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");