Skip to content

Commit

Permalink
Added hybrid_key_events mode ctrl + L
Browse files Browse the repository at this point in the history
  • Loading branch information
King-Slide committed Aug 28, 2018
1 parent ed3997a commit 26e2b8d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
46 changes: 23 additions & 23 deletions app/src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}
Expand Down
20 changes: 18 additions & 2 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

This comment has been minimized.

Copy link
@rom1v

rom1v Sep 9, 2018

(you leak the result of strdup)

// 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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -298,4 +314,4 @@ void input_manager_process_mouse_wheel(struct input_manager *input_manager,
LOGW("Cannot send mouse wheel event");
}
}
}
}
1 change: 1 addition & 0 deletions app/src/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 26e2b8d

Please sign in to comment.