Skip to content

Commit

Permalink
extended raw key event handling to numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
King-Slide committed Sep 16, 2018
1 parent 368e7a3 commit 26a2179
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to, Uint
}
// if ALT and META are not pressed, also handle letters and space
switch (from) {
MAP(SDLK_1, AKEYCODE_1);
MAP(SDLK_2, AKEYCODE_2);
MAP(SDLK_3, AKEYCODE_3);
MAP(SDLK_4, AKEYCODE_4);
MAP(SDLK_5, AKEYCODE_5);
MAP(SDLK_6, AKEYCODE_6);
MAP(SDLK_7, AKEYCODE_7);
MAP(SDLK_8, AKEYCODE_8);
MAP(SDLK_9, AKEYCODE_9);
MAP(SDLK_0, AKEYCODE_0);
MAP(SDLK_KP_1, AKEYCODE_NUMPAD_1);
MAP(SDLK_KP_2, AKEYCODE_NUMPAD_2);
MAP(SDLK_KP_3, AKEYCODE_NUMPAD_3);
MAP(SDLK_KP_4, AKEYCODE_NUMPAD_4);
MAP(SDLK_KP_5, AKEYCODE_NUMPAD_5);
MAP(SDLK_KP_6, AKEYCODE_NUMPAD_6);
MAP(SDLK_KP_7, AKEYCODE_NUMPAD_7);
MAP(SDLK_KP_8, AKEYCODE_NUMPAD_8);
MAP(SDLK_KP_9, AKEYCODE_NUMPAD_9);
MAP(SDLK_KP_0, AKEYCODE_0);
MAP(SDLK_a, AKEYCODE_A);
MAP(SDLK_b, AKEYCODE_B);
MAP(SDLK_c, AKEYCODE_C);
Expand Down
21 changes: 19 additions & 2 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ 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 == ' ') {
if (isalnum(c) || c == ' ') {
SDL_assert(event->text[1] == '\0');
// letters and space are handled as raw key event
// letters, numbers and space are handled as raw key event
return;
}
struct control_event control_event;
Expand Down Expand Up @@ -228,6 +228,23 @@ void input_manager_process_key(struct input_manager *input_manager,
return;
}

if (event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) {
// shift + numbers shouldn't be handled like raw_key_events in hybrid mode
switch (event->keysym.sym) {
case SDLK_1:
case SDLK_2:
case SDLK_3:
case SDLK_4:
case SDLK_5:
case SDLK_6:
case SDLK_7:
case SDLK_8:
case SDLK_9:
case SDLK_0:
return;
}
}

struct control_event control_event;
if (input_key_from_sdl_to_android(event, &control_event)) {
if (!controller_push_event(input_manager->controller, &control_event)) {
Expand Down

0 comments on commit 26a2179

Please sign in to comment.