diff --git a/app/src/convert.c b/app/src/convert.c index 9d947cb348..7d40b9386a 100644 --- a/app/src/convert.c +++ b/app/src/convert.c @@ -70,7 +70,7 @@ static enum android_metastate convert_meta_state(SDL_Keymod mod) { return autocomplete_metastate(metastate); } -static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) { +static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to, Uint16 mod) { switch (from) { MAP(SDLK_RETURN, AKEYCODE_ENTER); MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_ENTER); @@ -86,6 +86,39 @@ static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) { MAP(SDLK_LEFT, AKEYCODE_DPAD_LEFT); MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN); MAP(SDLK_UP, AKEYCODE_DPAD_UP); + } + if (mod & (KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI)) { + return SDL_FALSE; + } + // if ALT and META are not pressed, also handle letters and space + switch (from) { + MAP(SDLK_a, AKEYCODE_A); + MAP(SDLK_b, AKEYCODE_B); + MAP(SDLK_c, AKEYCODE_C); + MAP(SDLK_d, AKEYCODE_D); + MAP(SDLK_e, AKEYCODE_E); + MAP(SDLK_f, AKEYCODE_F); + MAP(SDLK_g, AKEYCODE_G); + MAP(SDLK_h, AKEYCODE_H); + MAP(SDLK_i, AKEYCODE_I); + MAP(SDLK_j, AKEYCODE_J); + MAP(SDLK_k, AKEYCODE_K); + MAP(SDLK_l, AKEYCODE_L); + MAP(SDLK_m, AKEYCODE_M); + MAP(SDLK_n, AKEYCODE_N); + MAP(SDLK_o, AKEYCODE_O); + MAP(SDLK_p, AKEYCODE_P); + MAP(SDLK_q, AKEYCODE_Q); + MAP(SDLK_r, AKEYCODE_R); + MAP(SDLK_s, AKEYCODE_S); + MAP(SDLK_t, AKEYCODE_T); + MAP(SDLK_u, AKEYCODE_U); + MAP(SDLK_v, AKEYCODE_V); + MAP(SDLK_w, AKEYCODE_W); + MAP(SDLK_x, AKEYCODE_X); + MAP(SDLK_y, AKEYCODE_Y); + MAP(SDLK_z, AKEYCODE_Z); + MAP(SDLK_SPACE, AKEYCODE_SPACE); FAIL; } } @@ -126,11 +159,12 @@ SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from, return SDL_FALSE; } - if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode)) { + Uint16 mod = from->keysym.mod; + if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode, mod)) { return SDL_FALSE; } - to->keycode_event.metastate = convert_meta_state(from->keysym.mod); + to->keycode_event.metastate = convert_meta_state(mod); return SDL_TRUE; } diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 797fd76421..af84c8f37e 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -1,5 +1,6 @@ #include "input_manager.h" +#include #include "convert.h" #include "lock_util.h" #include "log.h" @@ -129,6 +130,12 @@ static void clipboard_paste(struct controller *controller) { void input_manager_process_text_input(struct input_manager *input_manager, const SDL_TextInputEvent *event) { + char c = event->text[0]; + if (isalpha(c) || c == ' ') { + SDL_assert(event->text[1] == '\0'); + // letters and space are handled as raw key event + return; + } struct control_event control_event; control_event.type = CONTROL_EVENT_TYPE_TEXT; control_event.text_event.text = SDL_strdup(event->text);