Toggle "raw key events" via shortcut

The "raw key events" mode may need to be toggled while scrcpy is
running (e.g. to type text then play a game).

Remove the command-line argument and bind Ctrl+k to toggle the mode.
This commit is contained in:
Romain Vimont 2018-08-15 21:07:50 +02:00
parent 9de332bbe5
commit 7cd1e39766
5 changed files with 21 additions and 42 deletions

View File

@ -312,19 +312,6 @@ To show physical touches while scrcpy is running:
scrcpy -t 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: To run without installing:
```bash ```bash
@ -351,12 +338,15 @@ To run without installing:
| turn screen on | _Right-click²_ | | turn screen on | _Right-click²_ |
| paste computer clipboard to device | `Ctrl`+`v` | | paste computer clipboard to device | `Ctrl`+`v` |
| enable/disable FPS counter (on stdout) | `Ctrl`+`i` | | enable/disable FPS counter (on stdout) | `Ctrl`+`i` |
| toggle "raw key events" mode ([#87]) | `Ctrl`+`k` |
| install APK from computer | drag & drop APK file | | install APK from computer | drag & drop APK file |
| push file to `/sdcard/` | drag & drop non-APK file | | push file to `/sdcard/` | drag & drop non-APK file |
_¹Double-click on black borders to remove them._ _¹Double-click on black borders to remove them._
_²Right-click turns the screen on if it was off, presses BACK otherwise._ _²Right-click turns the screen on if it was off, presses BACK otherwise._
[#87]: https://github.com/Genymobile/scrcpy/issues/87
## Why _scrcpy_? ## Why _scrcpy_?

View File

@ -220,6 +220,13 @@ void input_manager_process_key(struct input_manager *input_manager,
switch_fps_counter_state(input_manager->frames); switch_fps_counter_state(input_manager->frames);
} }
return; 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; return;

View File

@ -14,7 +14,6 @@ struct args {
SDL_bool help; SDL_bool help;
SDL_bool version; SDL_bool version;
SDL_bool show_touches; SDL_bool show_touches;
SDL_bool raw_key_events;
Uint16 port; Uint16 port;
Uint16 max_size; Uint16 max_size;
Uint32 bit_rate; Uint32 bit_rate;
@ -37,11 +36,6 @@ static void usage(const char *arg0) {
" (typically, portrait for a phone, landscape for a tablet).\n" " (typically, portrait for a phone, landscape for a tablet).\n"
" Any --max-size value is computed on the cropped size.\n" " Any --max-size value is computed on the cropped size.\n"
"\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" " -h, --help\n"
" Print this help.\n" " Print this help.\n"
"\n" "\n"
@ -206,7 +200,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
static const struct option long_options[] = { static const struct option long_options[] = {
{"bit-rate", required_argument, NULL, 'b'}, {"bit-rate", required_argument, NULL, 'b'},
{"crop", required_argument, NULL, 'c'}, {"crop", required_argument, NULL, 'c'},
{"raw-key-events", no_argument, NULL, 'k'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"max-size", required_argument, NULL, 'm'}, {"max-size", required_argument, NULL, 'm'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
@ -216,7 +209,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{NULL, 0, NULL, 0 }, {NULL, 0, NULL, 0 },
}; };
int c; 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) { switch (c) {
case 'b': case 'b':
if (!parse_bit_rate(optarg, &args->bit_rate)) { 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': case 'c':
args->crop = optarg; args->crop = optarg;
break; break;
case 'k':
args->raw_key_events = SDL_TRUE;
break;
case 'h': case 'h':
args->help = SDL_TRUE; args->help = SDL_TRUE;
break; break;
@ -278,7 +268,6 @@ int main(int argc, char *argv[]) {
.help = SDL_FALSE, .help = SDL_FALSE,
.version = SDL_FALSE, .version = SDL_FALSE,
.show_touches = SDL_FALSE, .show_touches = SDL_FALSE,
.raw_key_events = SDL_FALSE,
.port = DEFAULT_LOCAL_PORT, .port = DEFAULT_LOCAL_PORT,
.max_size = DEFAULT_MAX_SIZE, .max_size = DEFAULT_MAX_SIZE,
.bit_rate = DEFAULT_BIT_RATE, .bit_rate = DEFAULT_BIT_RATE,
@ -316,7 +305,6 @@ int main(int argc, char *argv[]) {
.max_size = args.max_size, .max_size = args.max_size,
.bit_rate = args.bit_rate, .bit_rate = args.bit_rate,
.show_touches = args.show_touches, .show_touches = args.show_touches,
.raw_key_events = args.raw_key_events,
}; };
int res = scrcpy(&options) ? 0 : 1; int res = scrcpy(&options) ? 0 : 1;

View File

@ -35,6 +35,7 @@ static struct input_manager input_manager = {
.controller = &controller, .controller = &controller,
.frames = &frames, .frames = &frames,
.screen = &screen, .screen = &screen,
.raw_key_events = SDL_FALSE,
}; };
#if defined(__APPLE__) || defined(__WINDOWS__) #if defined(__APPLE__) || defined(__WINDOWS__)
@ -223,12 +224,6 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
show_touches_waited = SDL_TRUE; 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(); ret = event_loop();
LOGD("quit..."); LOGD("quit...");

View File

@ -10,7 +10,6 @@ struct scrcpy_options {
Uint16 max_size; Uint16 max_size;
Uint32 bit_rate; Uint32 bit_rate;
SDL_bool show_touches; SDL_bool show_touches;
SDL_bool raw_key_events; // ignore text input, forward key events instead
}; };
SDL_bool scrcpy(const struct scrcpy_options *options); SDL_bool scrcpy(const struct scrcpy_options *options);