diff --git a/app/src/hid_keyboard.h b/app/src/hid_keyboard.h index abc1ea5b24..89cca3ce0e 100644 --- a/app/src/hid_keyboard.h +++ b/app/src/hid_keyboard.h @@ -35,7 +35,7 @@ extern const unsigned char REPORT_DESC[REPORT_DESC_SIZE]; #define HID_MEDIA_REPORT_ID 0x02 /** * Media keys handle as mask so we define them here. - * FIXME: Some functions already exists on keyboard, maybe media key is useless? + * Currently not used because desktop environment catches them before window. */ #define HID_MEDIA_KEY_UNDEFINED 0x00 #define HID_MEDIA_KEY_NEXT (1 << 0) @@ -44,8 +44,8 @@ extern const unsigned char REPORT_DESC[REPORT_DESC_SIZE]; #define HID_MEDIA_KEY_EJECT (1 << 3) #define HID_MEDIA_KEY_PLAY_PAUSE (1 << 4) #define HID_MEDIA_KEY_MUTE (1 << 5) -#define HID_MEDIA_VOLUME_UP (1 << 6) -#define HID_MEDIA_VOLUME_DOWN (1 << 7) +#define HID_MEDIA_KEY_VOLUME_UP (1 << 6) +#define HID_MEDIA_KEY_VOLUME_DOWN (1 << 7) void hid_keyboard_init(void); void hid_keyboard_update_state(const SDL_KeyboardEvent *event); diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 9df10ce33f..8a36ba28d2 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -411,6 +411,29 @@ convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to, static void input_manager_process_key_inject(struct input_manager *im, const SDL_KeyboardEvent *event) { + struct controller *controller = im->controller; + struct control_msg msg; + if (convert_input_key(event, &msg, im->prefer_text, im->repeat)) { + if (!controller_push_msg(controller, &msg)) { + LOGW("Could not request 'inject keycode'"); + } + } +} + +static void +input_manager_process_key_hid(struct input_manager *im, + const SDL_KeyboardEvent *event) { + hid_keyboard_update_state(event); + const unsigned char *hid_event = hid_keyboard_get_hid_event(); + if (aoa_send_hid_event(im->usb_handle, hid_event, + HID_KEYBOARD_KEY_LENGTH) < 0) { + LOGW("Could not send HID event"); + } +} + +static void +input_manager_process_key(struct input_manager *im, + const SDL_KeyboardEvent *event) { // control: indicates the state of the command-line option --no-control bool control = im->control; @@ -562,7 +585,9 @@ input_manager_process_key_inject(struct input_manager *im, } if (event->repeat) { - if (!im->forward_key_repeat) { + // In USB HID protocol, key repeat is handle by host (Android in this case), + // so just ignore key repeat here. + if (!im->forward_key_repeat || im->use_hid_over_aoa) { return; } ++im->repeat; @@ -570,7 +595,9 @@ input_manager_process_key_inject(struct input_manager *im, im->repeat = 0; } - if (ctrl && !shift && keycode == SDLK_v && down && !repeat) { + // Ctrl+v works as paste in HID mode, I'd prefer not to modify it. + if (!im->use_hid_over_aoa && ctrl && !shift && keycode == SDLK_v && down && + !repeat) { if (im->legacy_paste) { // inject the text as input events clipboard_paste(controller); @@ -581,37 +608,6 @@ input_manager_process_key_inject(struct input_manager *im, set_device_clipboard(controller, false); } - struct control_msg msg; - if (convert_input_key(event, &msg, im->prefer_text, im->repeat)) { - if (!controller_push_msg(controller, &msg)) { - LOGW("Could not request 'inject keycode'"); - } - } -} - -static void -input_manager_process_key_hid(struct input_manager *im, - const SDL_KeyboardEvent *event) { - // Mirror-only mode. - if (!im->control) { - return; - } - // In USB HID protocol, key repeat is handle by host (Android in this case), - // so just ignore key repeat here. - if (event->repeat) { - return; - } - hid_keyboard_update_state(event); - const unsigned char *hid_event = hid_keyboard_get_hid_event(); - if (aoa_send_hid_event(im->usb_handle, hid_event, - HID_KEYBOARD_KEY_LENGTH) < 0) { - LOGW("Could not send HID event"); - } -} - -static void -input_manager_process_key(struct input_manager *im, - const SDL_KeyboardEvent *event) { if (im->use_hid_over_aoa) { input_manager_process_key_hid(im, event); } else {