Merge pull request #62886 from madmiraal/fix-59931-3.x
This commit is contained in:
commit
8cc8127bb1
|
@ -61,14 +61,17 @@ void AndroidInputHandler::process_event(Ref<InputEvent> &p_event) {
|
|||
input->parse_input_event(p_event);
|
||||
}
|
||||
|
||||
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_scancode, int p_physical_scancode, int p_unicode, bool p_pressed) {
|
||||
Ref<InputEventKey> ev;
|
||||
ev.instance();
|
||||
int val = p_unicode_char;
|
||||
unsigned int scancode = android_get_keysym(p_keycode);
|
||||
unsigned int phy_scancode = android_get_keysym(p_scancode);
|
||||
|
||||
switch (scancode) {
|
||||
unsigned int physical_scancode = godot_code_from_android_code(p_physical_scancode);
|
||||
unsigned int scancode = physical_scancode;
|
||||
if (p_scancode != 0) {
|
||||
scancode = godot_code_from_unicode(p_scancode);
|
||||
}
|
||||
|
||||
switch (physical_scancode) {
|
||||
case KEY_SHIFT: {
|
||||
shift_mem = p_pressed;
|
||||
} break;
|
||||
|
@ -81,25 +84,18 @@ void AndroidInputHandler::process_key_event(int p_keycode, int p_scancode, int p
|
|||
case KEY_META: {
|
||||
meta_mem = p_pressed;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ev->set_scancode(scancode);
|
||||
ev->set_physical_scancode(phy_scancode);
|
||||
|
||||
ev->set_unicode(val);
|
||||
ev->set_physical_scancode(physical_scancode);
|
||||
ev->set_unicode(p_unicode);
|
||||
ev->set_pressed(p_pressed);
|
||||
|
||||
_set_key_modifier_state(ev);
|
||||
|
||||
if (val == '\n') {
|
||||
ev->set_scancode(KEY_ENTER);
|
||||
} else if (val == 61448) {
|
||||
ev->set_scancode(KEY_BACKSPACE);
|
||||
ev->set_unicode(KEY_BACKSPACE);
|
||||
} else if (val == 61453) {
|
||||
ev->set_scancode(KEY_ENTER);
|
||||
ev->set_unicode(KEY_ENTER);
|
||||
} else if (p_scancode == 4) {
|
||||
if (p_physical_scancode == AKEYCODE_BACK) {
|
||||
if (MainLoop *main_loop = OS::get_singleton()->get_main_loop()) {
|
||||
main_loop->call_deferred("notification", MainLoop::NOTIFICATION_WM_GO_BACK_REQUEST);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
public:
|
||||
void process_event(Ref<InputEvent> &p_event);
|
||||
void process_joy_event(const 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_scancode, int p_physical_scancode, int p_unicode, bool p_pressed);
|
||||
void process_touch(int p_event, int p_pointer, const Vector<TouchPos> &p_points);
|
||||
void process_hover(int p_type, Point2 p_pos);
|
||||
void process_mouse_event(int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor, float event_horizontal_factor);
|
||||
|
|
|
@ -30,12 +30,49 @@
|
|||
|
||||
#include "android_keys_utils.h"
|
||||
|
||||
unsigned int android_get_keysym(unsigned int p_code) {
|
||||
for (int i = 0; _ak_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
|
||||
if (_ak_to_keycode[i].keycode == p_code) {
|
||||
return _ak_to_keycode[i].keysym;
|
||||
unsigned int godot_code_from_android_code(unsigned int p_code) {
|
||||
for (int i = 0; android_godot_code_pairs[i].android_code != AKEYCODE_MAX; i++) {
|
||||
if (android_godot_code_pairs[i].android_code == p_code) {
|
||||
return android_godot_code_pairs[i].godot_code;
|
||||
}
|
||||
}
|
||||
|
||||
return KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
unsigned int 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 == 0x7F) {
|
||||
return 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 code;
|
||||
}
|
||||
|
|
|
@ -34,129 +34,140 @@
|
|||
#include <android/input.h>
|
||||
#include <core/os/keyboard.h>
|
||||
|
||||
struct _WinTranslatePair {
|
||||
unsigned int keysym;
|
||||
unsigned int keycode;
|
||||
#define AKEYCODE_MAX 0xFFFF
|
||||
|
||||
struct AndroidGodotCodePair {
|
||||
unsigned int android_code = 0;
|
||||
unsigned int godot_code = 0;
|
||||
};
|
||||
|
||||
static _WinTranslatePair _ak_to_keycode[] = {
|
||||
{ KEY_TAB, AKEYCODE_TAB },
|
||||
{ KEY_ENTER, AKEYCODE_ENTER },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_LEFT },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_RIGHT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_LEFT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_RIGHT },
|
||||
{ KEY_MENU, AKEYCODE_MENU },
|
||||
{ KEY_PAUSE, AKEYCODE_MEDIA_PLAY_PAUSE },
|
||||
{ KEY_ESCAPE, AKEYCODE_BACK },
|
||||
{ KEY_SPACE, AKEYCODE_SPACE },
|
||||
{ KEY_PAGEUP, AKEYCODE_PAGE_UP },
|
||||
{ KEY_PAGEDOWN, AKEYCODE_PAGE_DOWN },
|
||||
{ KEY_HOME, AKEYCODE_HOME }, //(0x24)
|
||||
{ KEY_LEFT, AKEYCODE_DPAD_LEFT },
|
||||
{ KEY_UP, AKEYCODE_DPAD_UP },
|
||||
{ KEY_RIGHT, AKEYCODE_DPAD_RIGHT },
|
||||
{ KEY_DOWN, AKEYCODE_DPAD_DOWN },
|
||||
{ KEY_PERIODCENTERED, AKEYCODE_DPAD_CENTER },
|
||||
{ KEY_BACKSPACE, AKEYCODE_DEL },
|
||||
{ KEY_0, AKEYCODE_0 }, ////0 key
|
||||
{ KEY_1, AKEYCODE_1 }, ////1 key
|
||||
{ KEY_2, AKEYCODE_2 }, ////2 key
|
||||
{ KEY_3, AKEYCODE_3 }, ////3 key
|
||||
{ KEY_4, AKEYCODE_4 }, ////4 key
|
||||
{ KEY_5, AKEYCODE_5 }, ////5 key
|
||||
{ KEY_6, AKEYCODE_6 }, ////6 key
|
||||
{ KEY_7, AKEYCODE_7 }, ////7 key
|
||||
{ KEY_8, AKEYCODE_8 }, ////8 key
|
||||
{ KEY_9, AKEYCODE_9 }, ////9 key
|
||||
{ KEY_A, AKEYCODE_A }, ////A key
|
||||
{ KEY_B, AKEYCODE_B }, ////B key
|
||||
{ KEY_C, AKEYCODE_C }, ////C key
|
||||
{ KEY_D, AKEYCODE_D }, ////D key
|
||||
{ KEY_E, AKEYCODE_E }, ////E key
|
||||
{ KEY_F, AKEYCODE_F }, ////F key
|
||||
{ KEY_G, AKEYCODE_G }, ////G key
|
||||
{ KEY_H, AKEYCODE_H }, ////H key
|
||||
{ KEY_I, AKEYCODE_I }, ////I key
|
||||
{ KEY_J, AKEYCODE_J }, ////J key
|
||||
{ KEY_K, AKEYCODE_K }, ////K key
|
||||
{ KEY_L, AKEYCODE_L }, ////L key
|
||||
{ KEY_M, AKEYCODE_M }, ////M key
|
||||
{ KEY_N, AKEYCODE_N }, ////N key
|
||||
{ KEY_O, AKEYCODE_O }, ////O key
|
||||
{ KEY_P, AKEYCODE_P }, ////P key
|
||||
{ KEY_Q, AKEYCODE_Q }, ////Q key
|
||||
{ KEY_R, AKEYCODE_R }, ////R key
|
||||
{ KEY_S, AKEYCODE_S }, ////S key
|
||||
{ KEY_T, AKEYCODE_T }, ////T key
|
||||
{ KEY_U, AKEYCODE_U }, ////U key
|
||||
{ KEY_V, AKEYCODE_V }, ////V key
|
||||
{ KEY_W, AKEYCODE_W }, ////W key
|
||||
{ KEY_X, AKEYCODE_X }, ////X key
|
||||
{ KEY_Y, AKEYCODE_Y }, ////Y key
|
||||
{ KEY_Z, AKEYCODE_Z }, ////Z key
|
||||
{ KEY_HOMEPAGE, AKEYCODE_EXPLORER },
|
||||
{ KEY_LAUNCH0, AKEYCODE_BUTTON_A },
|
||||
{ KEY_LAUNCH1, AKEYCODE_BUTTON_B },
|
||||
{ KEY_LAUNCH2, AKEYCODE_BUTTON_C },
|
||||
{ KEY_LAUNCH3, AKEYCODE_BUTTON_X },
|
||||
{ KEY_LAUNCH4, AKEYCODE_BUTTON_Y },
|
||||
{ KEY_LAUNCH5, AKEYCODE_BUTTON_Z },
|
||||
{ KEY_LAUNCH6, AKEYCODE_BUTTON_L1 },
|
||||
{ KEY_LAUNCH7, AKEYCODE_BUTTON_R1 },
|
||||
{ KEY_LAUNCH8, AKEYCODE_BUTTON_L2 },
|
||||
{ KEY_LAUNCH9, AKEYCODE_BUTTON_R2 },
|
||||
{ KEY_LAUNCHA, AKEYCODE_BUTTON_THUMBL },
|
||||
{ KEY_LAUNCHB, AKEYCODE_BUTTON_THUMBR },
|
||||
{ KEY_LAUNCHC, AKEYCODE_BUTTON_START },
|
||||
{ KEY_LAUNCHD, AKEYCODE_BUTTON_SELECT },
|
||||
{ KEY_LAUNCHE, AKEYCODE_BUTTON_MODE },
|
||||
{ KEY_VOLUMEMUTE, AKEYCODE_MUTE },
|
||||
{ KEY_VOLUMEDOWN, AKEYCODE_VOLUME_DOWN },
|
||||
{ KEY_VOLUMEUP, AKEYCODE_VOLUME_UP },
|
||||
{ KEY_BACK, AKEYCODE_MEDIA_REWIND },
|
||||
{ KEY_FORWARD, AKEYCODE_MEDIA_FAST_FORWARD },
|
||||
{ KEY_MEDIANEXT, AKEYCODE_MEDIA_NEXT },
|
||||
{ KEY_MEDIAPREVIOUS, AKEYCODE_MEDIA_PREVIOUS },
|
||||
{ KEY_MEDIASTOP, AKEYCODE_MEDIA_STOP },
|
||||
{ KEY_PLUS, AKEYCODE_PLUS },
|
||||
{ KEY_EQUAL, AKEYCODE_EQUALS }, // the '+' key
|
||||
{ KEY_COMMA, AKEYCODE_COMMA }, // the ',' key
|
||||
{ KEY_MINUS, AKEYCODE_MINUS }, // the '-' key
|
||||
{ KEY_SLASH, AKEYCODE_SLASH }, // the '/?' key
|
||||
{ KEY_BACKSLASH, AKEYCODE_BACKSLASH },
|
||||
{ KEY_BRACKETLEFT, AKEYCODE_LEFT_BRACKET },
|
||||
{ KEY_BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET },
|
||||
{ KEY_CONTROL, AKEYCODE_CTRL_LEFT },
|
||||
{ KEY_CONTROL, AKEYCODE_CTRL_RIGHT },
|
||||
{ KEY_UNKNOWN, 0 }
|
||||
static AndroidGodotCodePair android_godot_code_pairs[] = {
|
||||
{ AKEYCODE_UNKNOWN, KEY_UNKNOWN }, // (0) Unknown key code.
|
||||
{ AKEYCODE_HOME, KEY_HOME }, // (3) Home key.
|
||||
{ AKEYCODE_BACK, KEY_BACK }, // (4) Back key.
|
||||
{ AKEYCODE_0, KEY_0 }, // (7) '0' key.
|
||||
{ AKEYCODE_1, KEY_1 }, // (8) '1' key.
|
||||
{ AKEYCODE_2, KEY_2 }, // (9) '2' key.
|
||||
{ AKEYCODE_3, KEY_3 }, // (10) '3' key.
|
||||
{ AKEYCODE_4, KEY_4 }, // (11) '4' key.
|
||||
{ AKEYCODE_5, KEY_5 }, // (12) '5' key.
|
||||
{ AKEYCODE_6, KEY_6 }, // (13) '6' key.
|
||||
{ AKEYCODE_7, KEY_7 }, // (14) '7' key.
|
||||
{ AKEYCODE_8, KEY_8 }, // (15) '8' key.
|
||||
{ AKEYCODE_9, KEY_9 }, // (16) '9' key.
|
||||
{ AKEYCODE_STAR, KEY_ASTERISK }, // (17) '*' key.
|
||||
{ AKEYCODE_POUND, KEY_NUMBERSIGN }, // (18) '#' key.
|
||||
{ AKEYCODE_DPAD_UP, KEY_UP }, // (19) Directional Pad Up key.
|
||||
{ AKEYCODE_DPAD_DOWN, KEY_DOWN }, // (20) Directional Pad Down key.
|
||||
{ AKEYCODE_DPAD_LEFT, KEY_LEFT }, // (21) Directional Pad Left key.
|
||||
{ AKEYCODE_DPAD_RIGHT, KEY_RIGHT }, // (22) Directional Pad Right key.
|
||||
{ AKEYCODE_VOLUME_UP, KEY_VOLUMEUP }, // (24) Volume Up key.
|
||||
{ AKEYCODE_VOLUME_DOWN, KEY_VOLUMEDOWN }, // (25) Volume Down key.
|
||||
{ AKEYCODE_CLEAR, KEY_CLEAR }, // (28) Clear key.
|
||||
{ AKEYCODE_A, KEY_A }, // (29) 'A' key.
|
||||
{ AKEYCODE_B, KEY_B }, // (30) 'B' key.
|
||||
{ AKEYCODE_C, KEY_C }, // (31) 'C' key.
|
||||
{ AKEYCODE_D, KEY_D }, // (32) 'D' key.
|
||||
{ AKEYCODE_E, KEY_E }, // (33) 'E' key.
|
||||
{ AKEYCODE_F, KEY_F }, // (34) 'F' key.
|
||||
{ AKEYCODE_G, KEY_G }, // (35) 'G' key.
|
||||
{ AKEYCODE_H, KEY_H }, // (36) 'H' key.
|
||||
{ AKEYCODE_I, KEY_I }, // (37) 'I' key.
|
||||
{ AKEYCODE_J, KEY_J }, // (38) 'J' key.
|
||||
{ AKEYCODE_K, KEY_K }, // (39) 'K' key.
|
||||
{ AKEYCODE_L, KEY_L }, // (40) 'L' key.
|
||||
{ AKEYCODE_M, KEY_M }, // (41) 'M' key.
|
||||
{ AKEYCODE_N, KEY_N }, // (42) 'N' key.
|
||||
{ AKEYCODE_O, KEY_O }, // (43) 'O' key.
|
||||
{ AKEYCODE_P, KEY_P }, // (44) 'P' key.
|
||||
{ AKEYCODE_Q, KEY_Q }, // (45) 'Q' key.
|
||||
{ AKEYCODE_R, KEY_R }, // (46) 'R' key.
|
||||
{ AKEYCODE_S, KEY_S }, // (47) 'S' key.
|
||||
{ AKEYCODE_T, KEY_T }, // (48) 'T' key.
|
||||
{ AKEYCODE_U, KEY_U }, // (49) 'U' key.
|
||||
{ AKEYCODE_V, KEY_V }, // (50) 'V' key.
|
||||
{ AKEYCODE_W, KEY_W }, // (51) 'W' key.
|
||||
{ AKEYCODE_X, KEY_X }, // (52) 'X' key.
|
||||
{ AKEYCODE_Y, KEY_Y }, // (53) 'Y' key.
|
||||
{ AKEYCODE_Z, KEY_Z }, // (54) 'Z' key.
|
||||
{ AKEYCODE_COMMA, KEY_COMMA }, // (55) ',’ key.
|
||||
{ AKEYCODE_PERIOD, KEY_PERIOD }, // (56) '.' key.
|
||||
{ AKEYCODE_ALT_LEFT, KEY_ALT }, // (57) Left Alt modifier key.
|
||||
{ AKEYCODE_ALT_RIGHT, KEY_ALT }, // (58) Right Alt modifier key.
|
||||
{ AKEYCODE_SHIFT_LEFT, KEY_SHIFT }, // (59) Left Shift modifier key.
|
||||
{ AKEYCODE_SHIFT_RIGHT, KEY_SHIFT }, // (60) Right Shift modifier key.
|
||||
{ AKEYCODE_TAB, KEY_TAB }, // (61) Tab key.
|
||||
{ AKEYCODE_SPACE, KEY_SPACE }, // (62) Space key.
|
||||
{ AKEYCODE_ENTER, KEY_ENTER }, // (66) Enter key.
|
||||
{ AKEYCODE_DEL, KEY_BACKSPACE }, // (67) Backspace key.
|
||||
{ AKEYCODE_GRAVE, KEY_QUOTELEFT }, // (68) '`' (backtick) key.
|
||||
{ AKEYCODE_MINUS, KEY_MINUS }, // (69) '-'.
|
||||
{ AKEYCODE_EQUALS, KEY_EQUAL }, // (70) '=' key.
|
||||
{ AKEYCODE_LEFT_BRACKET, KEY_BRACKETLEFT }, // (71) '[' key.
|
||||
{ AKEYCODE_RIGHT_BRACKET, KEY_BRACKETRIGHT }, // (72) ']' key.
|
||||
{ AKEYCODE_BACKSLASH, KEY_BACKSLASH }, // (73) '\' key.
|
||||
{ AKEYCODE_SEMICOLON, KEY_SEMICOLON }, // (74) ';' key.
|
||||
{ AKEYCODE_APOSTROPHE, KEY_APOSTROPHE }, // (75) ''' (apostrophe) key.
|
||||
{ AKEYCODE_SLASH, KEY_SLASH }, // (76) '/' key.
|
||||
{ AKEYCODE_AT, KEY_AT }, // (77) '@' key.
|
||||
{ AKEYCODE_PLUS, KEY_PLUS }, // (81) '+' key.
|
||||
{ AKEYCODE_MENU, KEY_MENU }, // (82) Menu key.
|
||||
{ AKEYCODE_SEARCH, KEY_SEARCH }, // (84) Search key.
|
||||
{ AKEYCODE_MEDIA_STOP, KEY_MEDIASTOP }, // (86) Stop media key.
|
||||
{ AKEYCODE_MEDIA_PREVIOUS, KEY_MEDIAPREVIOUS }, // (88) Play Previous media key.
|
||||
{ AKEYCODE_PAGE_UP, KEY_PAGEUP }, // (92) Page Up key.
|
||||
{ AKEYCODE_PAGE_DOWN, KEY_PAGEDOWN }, // (93) Page Down key.
|
||||
{ AKEYCODE_ESCAPE, KEY_ESCAPE }, // (111) Escape key.
|
||||
{ AKEYCODE_FORWARD_DEL, KEY_DELETE }, // (112) Forward Delete key.
|
||||
{ AKEYCODE_CTRL_LEFT, KEY_CONTROL }, // (113) Left Control modifier key.
|
||||
{ AKEYCODE_CTRL_RIGHT, KEY_CONTROL }, // (114) Right Control modifier key.
|
||||
{ AKEYCODE_CAPS_LOCK, KEY_CAPSLOCK }, // (115) Caps Lock key.
|
||||
{ AKEYCODE_SCROLL_LOCK, KEY_SCROLLLOCK }, // (116) Scroll Lock key.
|
||||
{ AKEYCODE_META_LEFT, KEY_META }, // (117) Left Meta modifier key.
|
||||
{ AKEYCODE_META_RIGHT, KEY_META }, // (118) Right Meta modifier key.
|
||||
{ AKEYCODE_SYSRQ, KEY_PRINT }, // (120) System Request / Print Screen key.
|
||||
{ AKEYCODE_BREAK, KEY_PAUSE }, // (121) Break / Pause key.
|
||||
{ AKEYCODE_INSERT, KEY_INSERT }, // (124) Insert key.
|
||||
{ AKEYCODE_FORWARD, KEY_FORWARD }, // (125) Forward key.
|
||||
{ AKEYCODE_MEDIA_PLAY, KEY_MEDIAPLAY }, // (126) Play media key.
|
||||
{ AKEYCODE_MEDIA_RECORD, KEY_MEDIARECORD }, // (130) Record media key.
|
||||
{ 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,
|
||||
*/
|
||||
|
||||
unsigned int android_get_keysym(unsigned int p_code);
|
||||
unsigned int godot_code_from_android_code(unsigned int p_code);
|
||||
unsigned int godot_code_from_unicode(unsigned int p_code);
|
||||
|
||||
#endif // ANDROID_KEYS_UTILS_H
|
||||
|
|
|
@ -140,7 +140,7 @@ public class GodotLib {
|
|||
/**
|
||||
* 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_scancode, int p_physical_scancode, int p_unicode, boolean p_pressed);
|
||||
|
||||
/**
|
||||
* Forward game device's key events from the main thread to the GL thread.
|
||||
|
|
|
@ -96,9 +96,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
|
|||
GodotLib.joybutton(godotJoyId, button, false);
|
||||
}
|
||||
} else {
|
||||
final int scanCode = event.getScanCode();
|
||||
final int chr = event.getUnicodeChar(0);
|
||||
GodotLib.key(keyCode, scanCode, chr, false);
|
||||
// getKeyCode(): The physical key that was pressed.
|
||||
// getScanCode(): Hardware key id. Device dependent and only used for debugging.
|
||||
// Godot's scancodes match the ASCII codes, so for single byte unicode characters,
|
||||
// we can use the unmodified unicode character to determine Godot's scancode.
|
||||
final int scancode = event.getUnicodeChar(0);
|
||||
final int physical_scancode = event.getKeyCode();
|
||||
final int unicode = event.getUnicodeChar();
|
||||
GodotLib.key(scancode, physical_scancode, unicode, false);
|
||||
};
|
||||
|
||||
return true;
|
||||
|
@ -131,9 +136,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
|
|||
GodotLib.joybutton(godotJoyId, button, true);
|
||||
}
|
||||
} else {
|
||||
final int scanCode = event.getScanCode();
|
||||
final int chr = event.getUnicodeChar(0);
|
||||
GodotLib.key(keyCode, scanCode, chr, true);
|
||||
final int scancode = event.getUnicodeChar(0);
|
||||
final int physical_scancode = event.getKeyCode();
|
||||
final int unicode = event.getUnicodeChar();
|
||||
GodotLib.key(scancode, physical_scancode, unicode, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -92,11 +92,9 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
|
||||
@Override
|
||||
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) {
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true);
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false);
|
||||
GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, true);
|
||||
GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, false);
|
||||
|
||||
if (mHasSelection) {
|
||||
mHasSelection = false;
|
||||
|
@ -107,8 +105,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
|
||||
@Override
|
||||
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];
|
||||
for (int i = start; i < start + count; ++i) {
|
||||
newChars[i - start] = pCharSequence.charAt(i);
|
||||
|
@ -119,8 +115,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
// Return keys are handled through action events
|
||||
continue;
|
||||
}
|
||||
GodotLib.key(0, 0, key, true);
|
||||
GodotLib.key(0, 0, key, false);
|
||||
GodotLib.key(key, 0, key, true);
|
||||
GodotLib.key(key, 0, key, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,16 +127,16 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
|
||||
for (int i = 0; i < characters.length(); i++) {
|
||||
final int ch = characters.codePointAt(i);
|
||||
GodotLib.key(0, 0, ch, true);
|
||||
GodotLib.key(0, 0, ch, false);
|
||||
GodotLib.key(ch, 0, ch, true);
|
||||
GodotLib.key(ch, 0, ch, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (pActionID == EditorInfo.IME_ACTION_DONE) {
|
||||
// Enter key has been pressed
|
||||
mView.queueEvent(() -> {
|
||||
GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true);
|
||||
GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false);
|
||||
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, true);
|
||||
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, false);
|
||||
});
|
||||
mView.requestFocus();
|
||||
return true;
|
||||
|
|
|
@ -399,11 +399,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_scancode, jint p_unicode_char, jboolean p_pressed) {
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_scancode, jint p_physical_scancode, jint p_unicode, jboolean p_pressed) {
|
||||
if (step.get() <= 0) {
|
||||
return;
|
||||
}
|
||||
input_handler->process_key_event(p_keycode, p_scancode, p_unicode_char, p_pressed);
|
||||
input_handler->process_key_event(p_scancode, p_physical_scancode, p_unicode, p_pressed);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
|
||||
|
|
|
@ -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_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_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_scancode, jint p_physical_scancode, 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_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);
|
||||
|
|
Loading…
Reference in New Issue