From 73a5311ac6c6570f1c9d23cd943c8d9aa0b281fe Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 10 Feb 2022 09:01:31 +0100 Subject: [PATCH] Forbid HID input without OTG on Windows On Windows, if the adb daemon is running, opening the USB device will necessarily fail, so HID input is not possible. Refs #2773 PR #3011 --- app/src/cli.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/cli.c b/app/src/cli.c index d8ae4f5385..482896781c 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -1680,6 +1680,18 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], } #ifdef HAVE_USB + +# ifdef _WIN32 + if (!opts->otg && (opts->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID + || opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_HID)) { + LOGE("On Windows, it is not possible to open a USB device already open " + "by another process (like adb)."); + LOGE("Therefore, -K/--hid-keyboard and -M/--hid-mouse may only work in " + "OTG mode (--otg)."); + return false; + } +# endif + if (opts->otg) { // OTG mode is compatible with only very few options. // Only report obvious errors.