Handle alpha and space chars as raw events
To handle special chars, text is handled as text input instead of key events. However, this breaks the separation of DOWN and UP key events. As a compromise, send letters and space as key events, to preserve original DOWN/UP events, but send other text input events as text, to be able to send "special" characters. Fixes <https://github.com/Genymobile/scrcpy/issues/87>. Suggested-by: pete1414 Suggested-by: King-Slide <kingslide@gmail.com>
This commit is contained in:
parent
52e2c60190
commit
411aa4fcfd
2 changed files with 44 additions and 3 deletions
|
@ -70,7 +70,7 @@ static enum android_metastate convert_meta_state(SDL_Keymod mod) {
|
||||||
return autocomplete_metastate(metastate);
|
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) {
|
switch (from) {
|
||||||
MAP(SDLK_RETURN, AKEYCODE_ENTER);
|
MAP(SDLK_RETURN, AKEYCODE_ENTER);
|
||||||
MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_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_LEFT, AKEYCODE_DPAD_LEFT);
|
||||||
MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN);
|
MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN);
|
||||||
MAP(SDLK_UP, AKEYCODE_DPAD_UP);
|
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;
|
FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,11 +159,12 @@ SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
|
||||||
return SDL_FALSE;
|
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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
to->keycode_event.metastate = convert_meta_state(from->keysym.mod);
|
to->keycode_event.metastate = convert_meta_state(mod);
|
||||||
|
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "input_manager.h"
|
#include "input_manager.h"
|
||||||
|
|
||||||
|
#include <SDL2/SDL_assert.h>
|
||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.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,
|
void input_manager_process_text_input(struct input_manager *input_manager,
|
||||||
const SDL_TextInputEvent *event) {
|
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;
|
struct control_event control_event;
|
||||||
control_event.type = CONTROL_EVENT_TYPE_TEXT;
|
control_event.type = CONTROL_EVENT_TYPE_TEXT;
|
||||||
control_event.text_event.text = SDL_strdup(event->text);
|
control_event.text_event.text = SDL_strdup(event->text);
|
||||||
|
|
Loading…
Reference in a new issue