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

Merge pull request #62885 from madmiraal/fix-59931

This commit is contained in:
Rémi Verschelde
2022-08-08 15:53:48 +02:00
committed by GitHub
9 changed files with 224 additions and 177 deletions

View File

@@ -56,10 +56,10 @@ void AndroidInputHandler::_set_key_modifier_state(Ref<InputEventWithModifiers> e
ev->set_ctrl_pressed(control_mem); ev->set_ctrl_pressed(control_mem);
} }
void AndroidInputHandler::process_key_event(int p_keycode, int p_scancode, int p_unicode_char, bool p_pressed) { void AndroidInputHandler::process_key_event(int p_keycode, int p_physical_keycode, int p_unicode, bool p_pressed) {
static char32_t prev_wc = 0; static char32_t prev_wc = 0;
char32_t unicode = p_unicode_char; char32_t unicode = p_unicode;
if ((p_unicode_char & 0xfffffc00) == 0xd800) { if ((p_unicode & 0xfffffc00) == 0xd800) {
if (prev_wc != 0) { if (prev_wc != 0) {
ERR_PRINT("invalid utf16 surrogate input"); ERR_PRINT("invalid utf16 surrogate input");
} }
@@ -78,39 +78,38 @@ void AndroidInputHandler::process_key_event(int p_keycode, int p_scancode, int p
Ref<InputEventKey> ev; Ref<InputEventKey> ev;
ev.instantiate(); ev.instantiate();
int val = unicode;
Key keycode = android_get_keysym(p_keycode);
Key phy_keycode = android_get_keysym(p_scancode);
if (keycode == Key::SHIFT) { Key physical_keycode = godot_code_from_android_code(p_physical_keycode);
shift_mem = p_pressed; Key keycode = physical_keycode;
if (p_keycode != 0) {
keycode = godot_code_from_unicode(p_keycode);
} }
if (keycode == Key::ALT) {
alt_mem = p_pressed; switch (physical_keycode) {
} case Key::SHIFT: {
if (keycode == Key::CTRL) { shift_mem = p_pressed;
control_mem = p_pressed; } break;
} case Key::ALT: {
if (keycode == Key::META) { alt_mem = p_pressed;
meta_mem = p_pressed; } break;
case Key::CTRL: {
control_mem = p_pressed;
} break;
case Key::META: {
meta_mem = p_pressed;
} break;
default:
break;
} }
ev->set_keycode(keycode); ev->set_keycode(keycode);
ev->set_physical_keycode(phy_keycode); ev->set_physical_keycode(physical_keycode);
ev->set_unicode(val); ev->set_unicode(unicode);
ev->set_pressed(p_pressed); ev->set_pressed(p_pressed);
_set_key_modifier_state(ev); _set_key_modifier_state(ev);
if (val == '\n') { if (p_physical_keycode == AKEYCODE_BACK) {
ev->set_keycode(Key::ENTER);
} else if (val == 61448) {
ev->set_keycode(Key::BACKSPACE);
ev->set_unicode((char32_t)Key::BACKSPACE);
} else if (val == 61453) {
ev->set_keycode(Key::ENTER);
ev->set_unicode((char32_t)Key::ENTER);
} else if (p_keycode == 4) {
if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) { if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) {
dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST, true); dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST, true);
} }

View File

@@ -83,7 +83,7 @@ public:
void process_mouse_event(int input_device, int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor = 0, float event_horizontal_factor = 0); void process_mouse_event(int input_device, int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor = 0, float event_horizontal_factor = 0);
void process_double_tap(int event_android_button_mask, Point2 p_pos); void process_double_tap(int event_android_button_mask, Point2 p_pos);
void process_joy_event(JoypadEvent p_event); void process_joy_event(JoypadEvent p_event);
void process_key_event(int p_keycode, int p_scancode, int p_unicode_char, bool p_pressed); void process_key_event(int p_keycode, int p_physical_keycode, int p_unicode, bool p_pressed);
}; };
#endif // ANDROID_INPUT_HANDLER_H #endif // ANDROID_INPUT_HANDLER_H

View File

@@ -30,12 +30,49 @@
#include "android_keys_utils.h" #include "android_keys_utils.h"
Key android_get_keysym(unsigned int p_code) { Key godot_code_from_android_code(unsigned int p_code) {
for (int i = 0; _ak_to_keycode[i].keysym != Key::UNKNOWN; i++) { for (int i = 0; android_godot_code_pairs[i].android_code != AKEYCODE_MAX; i++) {
if (_ak_to_keycode[i].keycode == p_code) { if (android_godot_code_pairs[i].android_code == p_code) {
return _ak_to_keycode[i].keysym; return android_godot_code_pairs[i].godot_code;
} }
} }
return Key::UNKNOWN; 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

@@ -34,129 +34,140 @@
#include <android/input.h> #include <android/input.h>
#include <core/os/keyboard.h> #include <core/os/keyboard.h>
struct _WinTranslatePair { #define AKEYCODE_MAX 0xFFFF
Key keysym = Key::NONE;
unsigned int keycode = 0; struct AndroidGodotCodePair {
unsigned int android_code = 0;
Key godot_code = Key::NONE;
}; };
static _WinTranslatePair _ak_to_keycode[] = { static AndroidGodotCodePair android_godot_code_pairs[] = {
{ Key::TAB, AKEYCODE_TAB }, { AKEYCODE_UNKNOWN, Key::UNKNOWN }, // (0) Unknown key code.
{ Key::ENTER, AKEYCODE_ENTER }, { AKEYCODE_HOME, Key::HOME }, // (3) Home key.
{ Key::SHIFT, AKEYCODE_SHIFT_LEFT }, { AKEYCODE_BACK, Key::BACK }, // (4) Back key.
{ Key::SHIFT, AKEYCODE_SHIFT_RIGHT }, { AKEYCODE_0, Key::KEY_0 }, // (7) '0' key.
{ Key::ALT, AKEYCODE_ALT_LEFT }, { AKEYCODE_1, Key::KEY_1 }, // (8) '1' key.
{ Key::ALT, AKEYCODE_ALT_RIGHT }, { AKEYCODE_2, Key::KEY_2 }, // (9) '2' key.
{ Key::MENU, AKEYCODE_MENU }, { AKEYCODE_3, Key::KEY_3 }, // (10) '3' key.
{ Key::PAUSE, AKEYCODE_MEDIA_PLAY_PAUSE }, { AKEYCODE_4, Key::KEY_4 }, // (11) '4' key.
{ Key::ESCAPE, AKEYCODE_BACK }, { AKEYCODE_5, Key::KEY_5 }, // (12) '5' key.
{ Key::SPACE, AKEYCODE_SPACE }, { AKEYCODE_6, Key::KEY_6 }, // (13) '6' key.
{ Key::PAGEUP, AKEYCODE_PAGE_UP }, { AKEYCODE_7, Key::KEY_7 }, // (14) '7' key.
{ Key::PAGEDOWN, AKEYCODE_PAGE_DOWN }, { AKEYCODE_8, Key::KEY_8 }, // (15) '8' key.
{ Key::HOME, AKEYCODE_HOME }, //(0x24) { AKEYCODE_9, Key::KEY_9 }, // (16) '9' key.
{ Key::LEFT, AKEYCODE_DPAD_LEFT }, { AKEYCODE_STAR, Key::ASTERISK }, // (17) '*' key.
{ Key::UP, AKEYCODE_DPAD_UP }, { AKEYCODE_POUND, Key::NUMBERSIGN }, // (18) '#' key.
{ Key::RIGHT, AKEYCODE_DPAD_RIGHT }, { AKEYCODE_DPAD_UP, Key::UP }, // (19) Directional Pad Up key.
{ Key::DOWN, AKEYCODE_DPAD_DOWN }, { AKEYCODE_DPAD_DOWN, Key::DOWN }, // (20) Directional Pad Down key.
{ Key::PERIODCENTERED, AKEYCODE_DPAD_CENTER }, { AKEYCODE_DPAD_LEFT, Key::LEFT }, // (21) Directional Pad Left key.
{ Key::BACKSPACE, AKEYCODE_DEL }, { AKEYCODE_DPAD_RIGHT, Key::RIGHT }, // (22) Directional Pad Right key.
{ Key::KEY_0, AKEYCODE_0 }, { AKEYCODE_VOLUME_UP, Key::VOLUMEUP }, // (24) Volume Up key.
{ Key::KEY_1, AKEYCODE_1 }, { AKEYCODE_VOLUME_DOWN, Key::VOLUMEDOWN }, // (25) Volume Down key.
{ Key::KEY_2, AKEYCODE_2 }, { AKEYCODE_CLEAR, Key::CLEAR }, // (28) Clear key.
{ Key::KEY_3, AKEYCODE_3 }, { AKEYCODE_A, Key::A }, // (29) 'A' key.
{ Key::KEY_4, AKEYCODE_4 }, { AKEYCODE_B, Key::B }, // (30) 'B' key.
{ Key::KEY_5, AKEYCODE_5 }, { AKEYCODE_C, Key::C }, // (31) 'C' key.
{ Key::KEY_6, AKEYCODE_6 }, { AKEYCODE_D, Key::D }, // (32) 'D' key.
{ Key::KEY_7, AKEYCODE_7 }, { AKEYCODE_E, Key::E }, // (33) 'E' key.
{ Key::KEY_8, AKEYCODE_8 }, { AKEYCODE_F, Key::F }, // (34) 'F' key.
{ Key::KEY_9, AKEYCODE_9 }, { AKEYCODE_G, Key::G }, // (35) 'G' key.
{ Key::A, AKEYCODE_A }, { AKEYCODE_H, Key::H }, // (36) 'H' key.
{ Key::B, AKEYCODE_B }, { AKEYCODE_I, Key::I }, // (37) 'I' key.
{ Key::C, AKEYCODE_C }, { AKEYCODE_J, Key::J }, // (38) 'J' key.
{ Key::D, AKEYCODE_D }, { AKEYCODE_K, Key::K }, // (39) 'K' key.
{ Key::E, AKEYCODE_E }, { AKEYCODE_L, Key::L }, // (40) 'L' key.
{ Key::F, AKEYCODE_F }, { AKEYCODE_M, Key::M }, // (41) 'M' key.
{ Key::G, AKEYCODE_G }, { AKEYCODE_N, Key::N }, // (42) 'N' key.
{ Key::H, AKEYCODE_H }, { AKEYCODE_O, Key::O }, // (43) 'O' key.
{ Key::I, AKEYCODE_I }, { AKEYCODE_P, Key::P }, // (44) 'P' key.
{ Key::J, AKEYCODE_J }, { AKEYCODE_Q, Key::Q }, // (45) 'Q' key.
{ Key::K, AKEYCODE_K }, { AKEYCODE_R, Key::R }, // (46) 'R' key.
{ Key::L, AKEYCODE_L }, { AKEYCODE_S, Key::S }, // (47) 'S' key.
{ Key::M, AKEYCODE_M }, { AKEYCODE_T, Key::T }, // (48) 'T' key.
{ Key::N, AKEYCODE_N }, { AKEYCODE_U, Key::U }, // (49) 'U' key.
{ Key::O, AKEYCODE_O }, { AKEYCODE_V, Key::V }, // (50) 'V' key.
{ Key::P, AKEYCODE_P }, { AKEYCODE_W, Key::W }, // (51) 'W' key.
{ Key::Q, AKEYCODE_Q }, { AKEYCODE_X, Key::X }, // (52) 'X' key.
{ Key::R, AKEYCODE_R }, { AKEYCODE_Y, Key::Y }, // (53) 'Y' key.
{ Key::S, AKEYCODE_S }, { AKEYCODE_Z, Key::Z }, // (54) 'Z' key.
{ Key::T, AKEYCODE_T }, { AKEYCODE_COMMA, Key::COMMA }, // (55) ', key.
{ Key::U, AKEYCODE_U }, { AKEYCODE_PERIOD, Key::PERIOD }, // (56) '.' key.
{ Key::V, AKEYCODE_V }, { AKEYCODE_ALT_LEFT, Key::ALT }, // (57) Left Alt modifier key.
{ Key::W, AKEYCODE_W }, { AKEYCODE_ALT_RIGHT, Key::ALT }, // (58) Right Alt modifier key.
{ Key::X, AKEYCODE_X }, { AKEYCODE_SHIFT_LEFT, Key::SHIFT }, // (59) Left Shift modifier key.
{ Key::Y, AKEYCODE_Y }, { AKEYCODE_SHIFT_RIGHT, Key::SHIFT }, // (60) Right Shift modifier key.
{ Key::Z, AKEYCODE_Z }, { AKEYCODE_TAB, Key::TAB }, // (61) Tab key.
{ Key::HOMEPAGE, AKEYCODE_EXPLORER }, { AKEYCODE_SPACE, Key::SPACE }, // (62) Space key.
{ Key::LAUNCH0, AKEYCODE_BUTTON_A }, { AKEYCODE_ENTER, Key::ENTER }, // (66) Enter key.
{ Key::LAUNCH1, AKEYCODE_BUTTON_B }, { AKEYCODE_DEL, Key::BACKSPACE }, // (67) Backspace key.
{ Key::LAUNCH2, AKEYCODE_BUTTON_C }, { AKEYCODE_GRAVE, Key::QUOTELEFT }, // (68) '`' (backtick) key.
{ Key::LAUNCH3, AKEYCODE_BUTTON_X }, { AKEYCODE_MINUS, Key::MINUS }, // (69) '-'.
{ Key::LAUNCH4, AKEYCODE_BUTTON_Y }, { AKEYCODE_EQUALS, Key::EQUAL }, // (70) '=' key.
{ Key::LAUNCH5, AKEYCODE_BUTTON_Z }, { AKEYCODE_LEFT_BRACKET, Key::BRACKETLEFT }, // (71) '[' key.
{ Key::LAUNCH6, AKEYCODE_BUTTON_L1 }, { AKEYCODE_RIGHT_BRACKET, Key::BRACKETRIGHT }, // (72) ']' key.
{ Key::LAUNCH7, AKEYCODE_BUTTON_R1 }, { AKEYCODE_BACKSLASH, Key::BACKSLASH }, // (73) '\' key.
{ Key::LAUNCH8, AKEYCODE_BUTTON_L2 }, { AKEYCODE_SEMICOLON, Key::SEMICOLON }, // (74) ';' key.
{ Key::LAUNCH9, AKEYCODE_BUTTON_R2 }, { AKEYCODE_APOSTROPHE, Key::APOSTROPHE }, // (75) ''' (apostrophe) key.
{ Key::LAUNCHA, AKEYCODE_BUTTON_THUMBL }, { AKEYCODE_SLASH, Key::SLASH }, // (76) '/' key.
{ Key::LAUNCHB, AKEYCODE_BUTTON_THUMBR }, { AKEYCODE_AT, Key::AT }, // (77) '@' key.
{ Key::LAUNCHC, AKEYCODE_BUTTON_START }, { AKEYCODE_PLUS, Key::PLUS }, // (81) '+' key.
{ Key::LAUNCHD, AKEYCODE_BUTTON_SELECT }, { AKEYCODE_MENU, Key::MENU }, // (82) Menu key.
{ Key::LAUNCHE, AKEYCODE_BUTTON_MODE }, { AKEYCODE_SEARCH, Key::SEARCH }, // (84) Search key.
{ Key::VOLUMEMUTE, AKEYCODE_MUTE }, { AKEYCODE_MEDIA_STOP, Key::MEDIASTOP }, // (86) Stop media key.
{ Key::VOLUMEDOWN, AKEYCODE_VOLUME_DOWN }, { AKEYCODE_MEDIA_PREVIOUS, Key::MEDIAPREVIOUS }, // (88) Play Previous media key.
{ Key::VOLUMEUP, AKEYCODE_VOLUME_UP }, { AKEYCODE_PAGE_UP, Key::PAGEUP }, // (92) Page Up key.
{ Key::BACK, AKEYCODE_MEDIA_REWIND }, { AKEYCODE_PAGE_DOWN, Key::PAGEDOWN }, // (93) Page Down key.
{ Key::FORWARD, AKEYCODE_MEDIA_FAST_FORWARD }, { AKEYCODE_ESCAPE, Key::ESCAPE }, // (111) Escape key.
{ Key::MEDIANEXT, AKEYCODE_MEDIA_NEXT }, { AKEYCODE_FORWARD_DEL, Key::KEY_DELETE }, // (112) Forward Delete key.
{ Key::MEDIAPREVIOUS, AKEYCODE_MEDIA_PREVIOUS }, { AKEYCODE_CTRL_LEFT, Key::CTRL }, // (113) Left Control modifier key.
{ Key::MEDIASTOP, AKEYCODE_MEDIA_STOP }, { AKEYCODE_CTRL_RIGHT, Key::CTRL }, // (114) Right Control modifier key.
{ Key::PLUS, AKEYCODE_PLUS }, { AKEYCODE_CAPS_LOCK, Key::CAPSLOCK }, // (115) Caps Lock key.
{ Key::EQUAL, AKEYCODE_EQUALS }, // the '+' key { AKEYCODE_SCROLL_LOCK, Key::SCROLLLOCK }, // (116) Scroll Lock key.
{ Key::COMMA, AKEYCODE_COMMA }, // the ',' key { AKEYCODE_META_LEFT, Key::META }, // (117) Left Meta modifier key.
{ Key::MINUS, AKEYCODE_MINUS }, // the '-' key { AKEYCODE_META_RIGHT, Key::META }, // (118) Right Meta modifier key.
{ Key::SLASH, AKEYCODE_SLASH }, // the '/?' key { AKEYCODE_SYSRQ, Key::PRINT }, // (120) System Request / Print Screen key.
{ Key::BACKSLASH, AKEYCODE_BACKSLASH }, { AKEYCODE_BREAK, Key::PAUSE }, // (121) Break / Pause key.
{ Key::BRACKETLEFT, AKEYCODE_LEFT_BRACKET }, { AKEYCODE_INSERT, Key::INSERT }, // (124) Insert key.
{ Key::BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET }, { AKEYCODE_FORWARD, Key::FORWARD }, // (125) Forward key.
{ Key::CTRL, AKEYCODE_CTRL_LEFT }, { AKEYCODE_MEDIA_PLAY, Key::MEDIAPLAY }, // (126) Play media key.
{ Key::CTRL, AKEYCODE_CTRL_RIGHT }, { AKEYCODE_MEDIA_RECORD, Key::MEDIARECORD }, // (130) Record media key.
{ Key::UNKNOWN, 0 } { AKEYCODE_F1, Key::F1 }, // (131) F1 key.
{ AKEYCODE_F2, Key::F2 }, // (132) F2 key.
{ AKEYCODE_F3, Key::F3 }, // (133) F3 key.
{ AKEYCODE_F4, Key::F4 }, // (134) F4 key.
{ AKEYCODE_F5, Key::F5 }, // (135) F5 key.
{ AKEYCODE_F6, Key::F6 }, // (136) F6 key.
{ AKEYCODE_F7, Key::F7 }, // (137) F7 key.
{ AKEYCODE_F8, Key::F8 }, // (138) F8 key.
{ AKEYCODE_F9, Key::F9 }, // (139) F9 key.
{ AKEYCODE_F10, Key::F10 }, // (140) F10 key.
{ AKEYCODE_F11, Key::F11 }, // (141) F11 key.
{ AKEYCODE_F12, Key::F12 }, // (142) F12 key.
{ AKEYCODE_NUM_LOCK, Key::NUMLOCK }, // (143) Num Lock key.
{ AKEYCODE_NUMPAD_0, Key::KP_0 }, // (144) Numeric keypad '0' key.
{ AKEYCODE_NUMPAD_1, Key::KP_1 }, // (145) Numeric keypad '1' key.
{ AKEYCODE_NUMPAD_2, Key::KP_2 }, // (146) Numeric keypad '2' key.
{ AKEYCODE_NUMPAD_3, Key::KP_3 }, // (147) Numeric keypad '3' key.
{ AKEYCODE_NUMPAD_4, Key::KP_4 }, // (148) Numeric keypad '4' key.
{ AKEYCODE_NUMPAD_5, Key::KP_5 }, // (149) Numeric keypad '5' key.
{ AKEYCODE_NUMPAD_6, Key::KP_6 }, // (150) Numeric keypad '6' key.
{ AKEYCODE_NUMPAD_7, Key::KP_7 }, // (151) Numeric keypad '7' key.
{ AKEYCODE_NUMPAD_8, Key::KP_8 }, // (152) Numeric keypad '8' key.
{ AKEYCODE_NUMPAD_9, Key::KP_9 }, // (153) Numeric keypad '9' key.
{ AKEYCODE_NUMPAD_DIVIDE, Key::KP_DIVIDE }, // (154) Numeric keypad '/' key (for division).
{ AKEYCODE_NUMPAD_MULTIPLY, Key::KP_MULTIPLY }, // (155) Numeric keypad '*' key (for multiplication).
{ AKEYCODE_NUMPAD_SUBTRACT, Key::KP_SUBTRACT }, // (156) Numeric keypad '-' key (for subtraction).
{ AKEYCODE_NUMPAD_ADD, Key::KP_ADD }, // (157) Numeric keypad '+' key (for addition).
{ 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_YEN, Key::YEN }, // (216) Japanese Yen key.
{ AKEYCODE_HELP, Key::HELP }, // (259) Help key.
{ AKEYCODE_REFRESH, Key::REFRESH }, // (285) Refresh key.
{ AKEYCODE_MAX, Key::UNKNOWN }
}; };
/*
TODO: map these android key:
AKEYCODE_SOFT_LEFT = 1,
AKEYCODE_SOFT_RIGHT = 2,
AKEYCODE_CALL = 5,
AKEYCODE_ENDCALL = 6,
AKEYCODE_STAR = 17,
AKEYCODE_POUND = 18,
AKEYCODE_POWER = 26,
AKEYCODE_CAMERA = 27,
AKEYCODE_CLEAR = 28,
AKEYCODE_SYM = 63,
AKEYCODE_ENVELOPE = 65,
AKEYCODE_GRAVE = 68,
AKEYCODE_SEMICOLON = 74,
AKEYCODE_APOSTROPHE = 75,
AKEYCODE_AT = 77,
AKEYCODE_NUM = 78,
AKEYCODE_HEADSETHOOK = 79,
AKEYCODE_FOCUS = 80, // *Camera* focus
AKEYCODE_NOTIFICATION = 83,
AKEYCODE_SEARCH = 84,
AKEYCODE_PICTSYMBOLS = 94,
AKEYCODE_SWITCH_CHARSET = 95,
*/
Key android_get_keysym(unsigned int p_code); Key godot_code_from_android_code(unsigned int p_code);
Key godot_code_from_unicode(unsigned int p_code);
#endif // ANDROID_KEYS_UTILS_H #endif // ANDROID_KEYS_UTILS_H

View File

@@ -151,7 +151,7 @@ public class GodotLib {
/** /**
* Forward regular key events from the main thread to the GL thread. * Forward regular key events from the main thread to the GL thread.
*/ */
public static native void key(int p_keycode, int p_scancode, int p_unicode_char, boolean p_pressed); public static native void key(int p_keycode, int p_physical_keycode, int p_unicode, boolean p_pressed);
/** /**
* Forward game device's key events from the main thread to the GL thread. * Forward game device's key events from the main thread to the GL thread.

View File

@@ -96,10 +96,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
GodotLib.joybutton(godotJoyId, button, false); GodotLib.joybutton(godotJoyId, button, false);
} }
} else { } else {
final int scanCode = event.getScanCode(); // getKeyCode(): The physical key that was pressed.
final int chr = event.getUnicodeChar(0); // Godot's keycodes match the ASCII codes, so for single byte unicode characters,
GodotLib.key(keyCode, scanCode, chr, false); // 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);
};
return true; return true;
} }
@@ -131,9 +135,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
GodotLib.joybutton(godotJoyId, button, true); GodotLib.joybutton(godotJoyId, button, true);
} }
} else { } else {
final int scanCode = event.getScanCode(); final int keycode = event.getUnicodeChar(0);
final int chr = event.getUnicodeChar(0); final int physical_keycode = event.getKeyCode();
GodotLib.key(keyCode, scanCode, chr, true); final int unicode = event.getUnicodeChar();
GodotLib.key(keycode, physical_keycode, unicode, true);
} }
return true; return true;

View File

@@ -92,11 +92,9 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override @Override
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) { public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true); GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, true);
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false); GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, false);
if (mHasSelection) { if (mHasSelection) {
mHasSelection = false; mHasSelection = false;
@@ -107,8 +105,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override @Override
public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) { public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) {
//Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before);
final int[] newChars = new int[count]; final int[] newChars = new int[count];
for (int i = start; i < start + count; ++i) { for (int i = start; i < start + count; ++i) {
newChars[i - start] = pCharSequence.charAt(i); newChars[i - start] = pCharSequence.charAt(i);
@@ -119,8 +115,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
// Return keys are handled through action events // Return keys are handled through action events
continue; continue;
} }
GodotLib.key(0, 0, key, true); GodotLib.key(key, 0, key, true);
GodotLib.key(0, 0, key, false); GodotLib.key(key, 0, key, false);
} }
} }
@@ -131,16 +127,16 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
for (int i = 0; i < characters.length(); i++) { for (int i = 0; i < characters.length(); i++) {
final int ch = characters.codePointAt(i); final int ch = characters.codePointAt(i);
GodotLib.key(0, 0, ch, true); GodotLib.key(ch, 0, ch, true);
GodotLib.key(0, 0, ch, false); GodotLib.key(ch, 0, ch, false);
} }
} }
if (pActionID == EditorInfo.IME_ACTION_DONE) { if (pActionID == EditorInfo.IME_ACTION_DONE) {
// Enter key has been pressed // Enter key has been pressed
mRenderView.queueOnRenderThread(() -> { mRenderView.queueOnRenderThread(() -> {
GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true); GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, true);
GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false); GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, false);
}); });
mRenderView.getView().requestFocus(); mRenderView.getView().requestFocus();
return true; return true;

View File

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

View File

@@ -51,7 +51,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FI(JNIEn
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_scancode, jint p_unicode_char, jboolean p_pressed); 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_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, 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_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); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y);