From 26e2b8d747c15e1b98c00b804e19bae39a50af4b Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 28 Aug 2018 14:21:53 +0200 Subject: [PATCH] Added hybrid_key_events mode ctrl + L --- app/src/convert.c | 46 ++++++++++++++++++++--------------------- app/src/input_manager.c | 20 ++++++++++++++++-- app/src/input_manager.h | 1 + app/src/scrcpy.c | 1 + 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/src/convert.c b/app/src/convert.c index 489d03f0aa..2c862b3c31 100644 --- a/app/src/convert.c +++ b/app/src/convert.c @@ -74,13 +74,13 @@ static enum android_metastate convert_meta_state(SDL_Keymod mod) { static SDL_bool convert_text_keycode(SDL_Keycode from, enum android_keycode *to) { switch (from) { MAP(SDLK_SPACE, AKEYCODE_SPACE); - MAP(SDLK_HASH, AKEYCODE_POUND); - MAP(SDLK_QUOTE, AKEYCODE_APOSTROPHE); - MAP(SDLK_ASTERISK, AKEYCODE_STAR); - MAP(SDLK_COMMA, AKEYCODE_COMMA); - MAP(SDLK_MINUS, AKEYCODE_MINUS); - MAP(SDLK_PERIOD, AKEYCODE_PERIOD); - MAP(SDLK_SLASH, AKEYCODE_SLASH); + //MAP(SDLK_HASH, AKEYCODE_POUND); + //MAP(SDLK_QUOTE, AKEYCODE_APOSTROPHE); + //MAP(SDLK_ASTERISK, AKEYCODE_STAR); + //MAP(SDLK_COMMA, AKEYCODE_COMMA); + //MAP(SDLK_MINUS, AKEYCODE_MINUS); + //MAP(SDLK_PERIOD, AKEYCODE_PERIOD); + //MAP(SDLK_SLASH, AKEYCODE_SLASH); MAP(SDLK_0, AKEYCODE_0); MAP(SDLK_1, AKEYCODE_1); MAP(SDLK_2, AKEYCODE_2); @@ -91,13 +91,13 @@ static SDL_bool convert_text_keycode(SDL_Keycode from, enum android_keycode *to) MAP(SDLK_7, AKEYCODE_7); MAP(SDLK_8, AKEYCODE_8); MAP(SDLK_9, AKEYCODE_9); - MAP(SDLK_SEMICOLON, AKEYCODE_SEMICOLON); - MAP(SDLK_EQUALS, AKEYCODE_EQUALS); - MAP(SDLK_AT, AKEYCODE_AT); - MAP(SDLK_LEFTBRACKET, AKEYCODE_LEFT_BRACKET); - MAP(SDLK_BACKSLASH, AKEYCODE_BACKSLASH); - MAP(SDLK_RIGHTBRACKET, AKEYCODE_RIGHT_BRACKET); - MAP(SDLK_BACKQUOTE, AKEYCODE_GRAVE); + //MAP(SDLK_SEMICOLON, AKEYCODE_SEMICOLON); + //MAP(SDLK_EQUALS, AKEYCODE_EQUALS); + //MAP(SDLK_AT, AKEYCODE_AT); + //MAP(SDLK_LEFTBRACKET, AKEYCODE_LEFT_BRACKET); + //MAP(SDLK_BACKSLASH, AKEYCODE_BACKSLASH); + //MAP(SDLK_RIGHTBRACKET, AKEYCODE_RIGHT_BRACKET); + //MAP(SDLK_BACKQUOTE, AKEYCODE_GRAVE); MAP(SDLK_a, AKEYCODE_A); MAP(SDLK_b, AKEYCODE_B); MAP(SDLK_c, AKEYCODE_C); @@ -124,7 +124,7 @@ static SDL_bool convert_text_keycode(SDL_Keycode from, enum android_keycode *to) MAP(SDLK_x, AKEYCODE_X); MAP(SDLK_y, AKEYCODE_Y); MAP(SDLK_z, AKEYCODE_Z); - MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_ENTER); + //MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_ENTER); MAP(SDLK_KP_1, AKEYCODE_NUMPAD_1); MAP(SDLK_KP_2, AKEYCODE_NUMPAD_2); MAP(SDLK_KP_3, AKEYCODE_NUMPAD_3); @@ -135,14 +135,14 @@ static SDL_bool convert_text_keycode(SDL_Keycode from, enum android_keycode *to) MAP(SDLK_KP_8, AKEYCODE_NUMPAD_8); MAP(SDLK_KP_9, AKEYCODE_NUMPAD_9); MAP(SDLK_KP_0, AKEYCODE_NUMPAD_0); - MAP(SDLK_KP_DIVIDE, AKEYCODE_NUMPAD_DIVIDE); - MAP(SDLK_KP_MULTIPLY, AKEYCODE_NUMPAD_MULTIPLY); - MAP(SDLK_KP_MINUS, AKEYCODE_NUMPAD_SUBTRACT); - MAP(SDLK_KP_PLUS, AKEYCODE_NUMPAD_ADD); - MAP(SDLK_KP_PERIOD, AKEYCODE_NUMPAD_DOT); - MAP(SDLK_KP_EQUALS, AKEYCODE_NUMPAD_EQUALS); - MAP(SDLK_KP_LEFTPAREN, AKEYCODE_NUMPAD_LEFT_PAREN); - MAP(SDLK_KP_RIGHTPAREN, AKEYCODE_NUMPAD_RIGHT_PAREN); + //MAP(SDLK_KP_DIVIDE, AKEYCODE_NUMPAD_DIVIDE); + //MAP(SDLK_KP_MULTIPLY, AKEYCODE_NUMPAD_MULTIPLY); + //MAP(SDLK_KP_MINUS, AKEYCODE_NUMPAD_SUBTRACT); + //MAP(SDLK_KP_PLUS, AKEYCODE_NUMPAD_ADD); + //MAP(SDLK_KP_PERIOD, AKEYCODE_NUMPAD_DOT); + //MAP(SDLK_KP_EQUALS, AKEYCODE_NUMPAD_EQUALS); + //MAP(SDLK_KP_LEFTPAREN, AKEYCODE_NUMPAD_LEFT_PAREN); + //MAP(SDLK_KP_RIGHTPAREN, AKEYCODE_NUMPAD_RIGHT_PAREN); FAIL; } } diff --git a/app/src/input_manager.c b/app/src/input_manager.c index e9d63bf199..72348fd424 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -133,6 +133,13 @@ void input_manager_process_text_input(struct input_manager *input_manager, // we will forward the raw key events instead return; } + // || SDL_strdup(event->text) == "\r" + char special_chars[] = " 0123456789abcdefghijklmnopqrstuvwxyz"; + if (input_manager->hybrid_key_events && strpbrk(special_chars, SDL_strdup(event->text)) != NULL) { + // we will forward the raw key events instead + return; + } + struct control_event control_event; control_event.type = CONTROL_EVENT_TYPE_TEXT; control_event.text_event.text = SDL_strdup(event->text); @@ -222,18 +229,27 @@ void input_manager_process_key(struct input_manager *input_manager, return; case SDLK_k: if (!repeat && event->type == SDL_KEYDOWN) { + input_manager->hybrid_key_events = SDL_FALSE; input_manager->raw_key_events ^= SDL_TRUE; // toggle LOGI("Raw key events mode %s", input_manager->raw_key_events ? "enabled" : "disabled"); } return; + case SDLK_l: + if (!repeat && event->type == SDL_KEYDOWN) { + input_manager->raw_key_events = SDL_FALSE; + input_manager->hybrid_key_events ^= SDL_TRUE; // toggle + LOGI("Hybrid key events mode %s", + input_manager->hybrid_key_events ? "enabled" : "disabled"); + } + return; } return; } struct control_event control_event; - SDL_bool raw_key_events = input_manager->raw_key_events; + SDL_bool raw_key_events = input_manager->raw_key_events | input_manager->hybrid_key_events; if (input_key_from_sdl_to_android(event, &control_event, raw_key_events)) { if (!controller_push_event(input_manager->controller, &control_event)) { LOGW("Cannot send control event"); @@ -298,4 +314,4 @@ void input_manager_process_mouse_wheel(struct input_manager *input_manager, LOGW("Cannot send mouse wheel event"); } } -} +} \ No newline at end of file diff --git a/app/src/input_manager.h b/app/src/input_manager.h index 2e4cd3646a..b83febe7ea 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -12,6 +12,7 @@ struct input_manager { struct frames *frames; struct screen *screen; SDL_bool raw_key_events; + SDL_bool hybrid_key_events; }; void input_manager_process_text_input(struct input_manager *input_manager, diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 64433b4730..147a7c2e17 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -36,6 +36,7 @@ static struct input_manager input_manager = { .frames = &frames, .screen = &screen, .raw_key_events = SDL_FALSE, + .hybrid_key_events = SDL_FALSE, }; #if defined(__APPLE__) || defined(__WINDOWS__)