diff --git a/README.md b/README.md index 3d3d0e91..9223f7b8 100644 --- a/README.md +++ b/README.md @@ -312,19 +312,6 @@ To show physical touches while scrcpy is running: scrcpy -t ``` -For playing games, it may be useful to enable "raw key events" (see [#87] and -[#127]): - -```bash -scrcpy -k -``` - -Note that in this mode, text inputs may not work as expected. As a workaround, -it is still possible to send text using copy-paste. - -[#87]: https://github.com/Genymobile/scrcpy/issues/87 -[#127]: https://github.com/Genymobile/scrcpy/issues/127 - To run without installing: ```bash @@ -351,12 +338,15 @@ To run without installing: | turn screen on | _Right-click²_ | | paste computer clipboard to device | `Ctrl`+`v` | | enable/disable FPS counter (on stdout) | `Ctrl`+`i` | + | toggle "raw key events" mode ([#87]) | `Ctrl`+`k` | | install APK from computer | drag & drop APK file | | push file to `/sdcard/` | drag & drop non-APK file | _¹Double-click on black borders to remove them._ _²Right-click turns the screen on if it was off, presses BACK otherwise._ +[#87]: https://github.com/Genymobile/scrcpy/issues/87 + ## Why _scrcpy_? diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 1cbc341a..e9d63bf1 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -220,6 +220,13 @@ void input_manager_process_key(struct input_manager *input_manager, switch_fps_counter_state(input_manager->frames); } return; + case SDLK_k: + if (!repeat && event->type == SDL_KEYDOWN) { + input_manager->raw_key_events ^= SDL_TRUE; // toggle + LOGI("Raw key events mode %s", + input_manager->raw_key_events ? "enabled" : "disabled"); + } + return; } return; diff --git a/app/src/main.c b/app/src/main.c index 6842fc59..1317da79 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -14,7 +14,6 @@ struct args { SDL_bool help; SDL_bool version; SDL_bool show_touches; - SDL_bool raw_key_events; Uint16 port; Uint16 max_size; Uint32 bit_rate; @@ -37,11 +36,6 @@ static void usage(const char *arg0) { " (typically, portrait for a phone, landscape for a tablet).\n" " Any --max-size value is computed on the cropped size.\n" "\n" - " -k, --raw-key-events\n" - " Send key events even for text keys, and ignore text input\n" - " events. This is useful when text keys are not used for\n" - " typing text, for example in video games.\n" - "\n" " -h, --help\n" " Print this help.\n" "\n" @@ -204,19 +198,18 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) { static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { static const struct option long_options[] = { - {"bit-rate", required_argument, NULL, 'b'}, - {"crop", required_argument, NULL, 'c'}, - {"raw-key-events", no_argument, NULL, 'k'}, - {"help", no_argument, NULL, 'h'}, - {"max-size", required_argument, NULL, 'm'}, - {"port", required_argument, NULL, 'p'}, - {"serial", required_argument, NULL, 's'}, - {"show-touches", no_argument, NULL, 't'}, - {"version", no_argument, NULL, 'v'}, - {NULL, 0, NULL, 0 }, + {"bit-rate", required_argument, NULL, 'b'}, + {"crop", required_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, + {"max-size", required_argument, NULL, 'm'}, + {"port", required_argument, NULL, 'p'}, + {"serial", required_argument, NULL, 's'}, + {"show-touches", no_argument, NULL, 't'}, + {"version", no_argument, NULL, 'v'}, + {NULL, 0, NULL, 0 }, }; int c; - while ((c = getopt_long(argc, argv, "b:c:khm:p:s:tv", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "b:c:hm:p:s:tv", long_options, NULL)) != -1) { switch (c) { case 'b': if (!parse_bit_rate(optarg, &args->bit_rate)) { @@ -226,9 +219,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { case 'c': args->crop = optarg; break; - case 'k': - args->raw_key_events = SDL_TRUE; - break; case 'h': args->help = SDL_TRUE; break; @@ -278,7 +268,6 @@ int main(int argc, char *argv[]) { .help = SDL_FALSE, .version = SDL_FALSE, .show_touches = SDL_FALSE, - .raw_key_events = SDL_FALSE, .port = DEFAULT_LOCAL_PORT, .max_size = DEFAULT_MAX_SIZE, .bit_rate = DEFAULT_BIT_RATE, @@ -316,7 +305,6 @@ int main(int argc, char *argv[]) { .max_size = args.max_size, .bit_rate = args.bit_rate, .show_touches = args.show_touches, - .raw_key_events = args.raw_key_events, }; int res = scrcpy(&options) ? 0 : 1; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 06c550a0..64433b47 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -35,6 +35,7 @@ static struct input_manager input_manager = { .controller = &controller, .frames = &frames, .screen = &screen, + .raw_key_events = SDL_FALSE, }; #if defined(__APPLE__) || defined(__WINDOWS__) @@ -223,12 +224,6 @@ SDL_bool scrcpy(const struct scrcpy_options *options) { show_touches_waited = SDL_TRUE; } - // configure the "raw key events" flag on the input manager - input_manager.raw_key_events = options->raw_key_events; - if (options->raw_key_events) { - LOGI("Raw key events mode enabled"); - } - ret = event_loop(); LOGD("quit..."); diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 9e5fd051..7ddabf28 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -10,7 +10,6 @@ struct scrcpy_options { Uint16 max_size; Uint32 bit_rate; SDL_bool show_touches; - SDL_bool raw_key_events; // ignore text input, forward key events instead }; SDL_bool scrcpy(const struct scrcpy_options *options);