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:
parent
9de332bbe5
commit
7cd1e39766
16
README.md
16
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_?
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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...");
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user