diff --git a/README.md b/README.md index e8b5446545..460ca3a988 100644 --- a/README.md +++ b/README.md @@ -548,6 +548,10 @@ into the device clipboard. As a consequence, any Android application could read its content. You should avoid to paste sensitive content (like passwords) that way. +Some devices do not behave as expected when setting the device clipboard +programmatically. An option `--legacy-paste` is provided to change the behavior +of Ctrl+v and MOD+v to also inject +the computer clipboard text as a sequence of key events. #### Pinch-to-zoom diff --git a/app/scrcpy.1 b/app/scrcpy.1 index e957a4d012..c69f2290d2 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -68,6 +68,12 @@ Start in fullscreen. .B \-h, \-\-help Print this help. +.TP +.B \-\-legacy\-paste +Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+Shift+v). + +This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically. + .TP .BI "\-\-lock\-video\-orientation " value Lock video orientation to \fIvalue\fR. Possible values are -1 (unlocked), 0, 1, 2 and 3. Natural device orientation is 0, and each increment adds a 90 degrees otation counterclockwise. diff --git a/app/src/cli.c b/app/src/cli.c index 41de8ca5dd..08fe71a38c 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -63,6 +63,12 @@ scrcpy_print_usage(const char *arg0) { " -h, --help\n" " Print this help.\n" "\n" + " --legacy-paste\n" + " Inject computer clipboard text as a sequence of key events\n" + " on Ctrl+v (like MOD+Shift+v).\n" + " This is a workaround for some devices not behaving as\n" + " expected when setting the device clipboard programmatically.\n" + "\n" " --lock-video-orientation value\n" " Lock video orientation to value.\n" " Possible values are -1 (unlocked), 0, 1, 2 and 3.\n" @@ -651,6 +657,7 @@ guess_record_format(const char *filename) { #define OPT_DISABLE_SCREENSAVER 1020 #define OPT_SHORTCUT_MOD 1021 #define OPT_NO_KEY_REPEAT 1022 +#define OPT_LEGACY_PASTE 1023 bool scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { @@ -666,6 +673,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { OPT_FORCE_ADB_FORWARD}, {"fullscreen", no_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, + {"legacy-paste", no_argument, NULL, OPT_LEGACY_PASTE}, {"lock-video-orientation", required_argument, NULL, OPT_LOCK_VIDEO_ORIENTATION}, {"max-fps", required_argument, NULL, OPT_MAX_FPS}, @@ -856,6 +864,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { return false; } break; + case OPT_LEGACY_PASTE: + opts->legacy_paste = true; + break; default: // getopt prints the error message on stderr return false; diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 962db1d3e7..2e95e3b1f8 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -60,6 +60,7 @@ input_manager_init(struct input_manager *im, im->control = options->control; im->forward_key_repeat = options->forward_key_repeat; im->prefer_text = options->prefer_text; + im->legacy_paste = options->legacy_paste; const struct sc_shortcut_mods *shortcut_mods = &options->shortcut_mods; assert(shortcut_mods->count); @@ -440,7 +441,7 @@ input_manager_process_key(struct input_manager *im, return; case SDLK_v: if (control && !repeat && down) { - if (shift) { + if (shift || im->legacy_paste) { // inject the text as input events clipboard_paste(controller); } else { @@ -504,6 +505,11 @@ input_manager_process_key(struct input_manager *im, } if (ctrl && !shift && keycode == SDLK_v && down && !repeat) { + if (im->legacy_paste) { + // inject the text as input events + clipboard_paste(controller); + return; + } // Synchronize the computer clipboard to the device clipboard before // sending Ctrl+v, to allow seamless copy-paste. set_device_clipboard(controller, false); diff --git a/app/src/input_manager.h b/app/src/input_manager.h index c3756e40cf..732d7eec36 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -25,6 +25,7 @@ struct input_manager { bool control; bool forward_key_repeat; bool prefer_text; + bool legacy_paste; struct { unsigned data[SC_MAX_SHORTCUT_MODS]; diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 86a2b57bc6..8b9102c6f6 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -79,6 +79,7 @@ struct scrcpy_options { bool force_adb_forward; bool disable_screensaver; bool forward_key_repeat; + bool legacy_paste; }; #define SCRCPY_OPTIONS_DEFAULT { \ @@ -123,6 +124,7 @@ struct scrcpy_options { .force_adb_forward = false, \ .disable_screensaver = false, \ .forward_key_repeat = true, \ + .legacy_paste = false, \ } bool