You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Merge pull request #18020 from bruvzg/input_fix_non_latin_and_add_hw_scancodes
Fix non-latin layout scancodes on Linux, adds access to physical scancodes.
This commit is contained in:
@@ -237,19 +237,31 @@ bool InputEventKey::is_pressed() const {
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void InputEventKey::set_scancode(uint32_t p_scancode) {
|
||||
void InputEventKey::set_keycode(uint32_t p_keycode) {
|
||||
|
||||
scancode = p_scancode;
|
||||
keycode = p_keycode;
|
||||
}
|
||||
uint32_t InputEventKey::get_scancode() const {
|
||||
|
||||
return scancode;
|
||||
uint32_t InputEventKey::get_keycode() const {
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
void InputEventKey::set_physical_keycode(uint32_t p_keycode) {
|
||||
|
||||
physical_keycode = p_keycode;
|
||||
}
|
||||
|
||||
uint32_t InputEventKey::get_physical_keycode() const {
|
||||
|
||||
return physical_keycode;
|
||||
}
|
||||
|
||||
void InputEventKey::set_unicode(uint32_t p_unicode) {
|
||||
|
||||
unicode = p_unicode;
|
||||
}
|
||||
|
||||
uint32_t InputEventKey::get_unicode() const {
|
||||
|
||||
return unicode;
|
||||
@@ -259,14 +271,30 @@ void InputEventKey::set_echo(bool p_enable) {
|
||||
|
||||
echo = p_enable;
|
||||
}
|
||||
|
||||
bool InputEventKey::is_echo() const {
|
||||
|
||||
return echo;
|
||||
}
|
||||
|
||||
uint32_t InputEventKey::get_scancode_with_modifiers() const {
|
||||
uint32_t InputEventKey::get_keycode_with_modifiers() const {
|
||||
|
||||
uint32_t sc = scancode;
|
||||
uint32_t sc = keycode;
|
||||
if (get_control())
|
||||
sc |= KEY_MASK_CTRL;
|
||||
if (get_alt())
|
||||
sc |= KEY_MASK_ALT;
|
||||
if (get_shift())
|
||||
sc |= KEY_MASK_SHIFT;
|
||||
if (get_metakey())
|
||||
sc |= KEY_MASK_META;
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
|
||||
|
||||
uint32_t sc = physical_keycode;
|
||||
if (get_control())
|
||||
sc |= KEY_MASK_CTRL;
|
||||
if (get_alt())
|
||||
@@ -281,7 +309,7 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const {
|
||||
|
||||
String InputEventKey::as_text() const {
|
||||
|
||||
String kc = keycode_get_string(scancode);
|
||||
String kc = keycode_get_string(keycode);
|
||||
if (kc == String())
|
||||
return kc;
|
||||
|
||||
@@ -306,10 +334,18 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
|
||||
if (key.is_null())
|
||||
return false;
|
||||
|
||||
uint32_t code = get_scancode_with_modifiers();
|
||||
uint32_t event_code = key->get_scancode_with_modifiers();
|
||||
bool match = false;
|
||||
if (get_keycode() == 0) {
|
||||
uint32_t code = get_physical_keycode_with_modifiers();
|
||||
uint32_t event_code = key->get_physical_keycode_with_modifiers();
|
||||
|
||||
bool match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
|
||||
match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code);
|
||||
} else {
|
||||
uint32_t code = get_keycode_with_modifiers();
|
||||
uint32_t event_code = key->get_keycode_with_modifiers();
|
||||
|
||||
match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
|
||||
}
|
||||
if (match) {
|
||||
if (p_pressed != NULL)
|
||||
*p_pressed = key->is_pressed();
|
||||
@@ -325,8 +361,8 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
|
||||
if (key.is_null())
|
||||
return false;
|
||||
|
||||
uint32_t code = get_scancode_with_modifiers();
|
||||
uint32_t event_code = key->get_scancode_with_modifiers();
|
||||
uint32_t code = get_keycode_with_modifiers();
|
||||
uint32_t event_code = key->get_keycode_with_modifiers();
|
||||
|
||||
return code == event_code;
|
||||
}
|
||||
@@ -335,18 +371,23 @@ void InputEventKey::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
|
||||
ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
|
||||
ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode);
|
||||
ClassDB::bind_method(D_METHOD("get_keycode"), &InputEventKey::get_keycode);
|
||||
|
||||
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_unicode", "unicode"), &InputEventKey::set_unicode);
|
||||
ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
|
||||
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);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
|
||||
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, "unicode"), "set_unicode", "get_unicode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
|
||||
}
|
||||
@@ -354,7 +395,8 @@ void InputEventKey::_bind_methods() {
|
||||
InputEventKey::InputEventKey() {
|
||||
|
||||
pressed = false;
|
||||
scancode = 0;
|
||||
keycode = 0;
|
||||
physical_keycode = 0;
|
||||
unicode = 0; ///unicode
|
||||
echo = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user