Skip to content

Commit

Permalink
Add --no-key-repeat cli option
Browse files Browse the repository at this point in the history
Add an option to avoid forwarding repeated key events.

PR #1623 <#1623>
Refs #1013 <#1013>

Signed-off-by: Romain Vimont <rom@rom1v.com>
  • Loading branch information
xeropresence authored and rom1v committed Aug 3, 2020
1 parent 65d06a3 commit 84f1d9e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ scrcpy --prefer-text
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343


#### Key repeat

By default, holding a key down generates repeated key events. This can cause
performance problems in some games, where these events are useless anyway.

To avoid forwarding repeated key events:

```bash
scrcpy --no-key-repeat
```


### File drop

#### Install APK
Expand Down
4 changes: 4 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Do not display device (only when screen recording is enabled).
.B \-\-no\-mipmaps
If the renderer is OpenGL 3.0+ or OpenGL ES 2.0+, then mipmaps are automatically generated to improve downscaling quality. This option disables the generation of mipmaps.

.TP
.B \-\-no\-key\-repeat
Do not forward repeated key events when a key is held down.

.TP
.BI "\-p, \-\-port " port[:port]
Set the TCP port (range) used by the client to listen.
Expand Down
8 changes: 8 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ scrcpy_print_usage(const char *arg0) {
" mipmaps are automatically generated to improve downscaling\n"
" quality. This option disables the generation of mipmaps.\n"
"\n"
" --no-key-repeat\n"
" Do not forward repeated key events when a key is held down.\n"
"\n"
" -p, --port port[:port]\n"
" Set the TCP port (range) used by the client to listen.\n"
" Default is %d:%d.\n"
Expand Down Expand Up @@ -642,6 +645,7 @@ guess_record_format(const char *filename) {
#define OPT_FORCE_ADB_FORWARD 1019
#define OPT_DISABLE_SCREENSAVER 1020
#define OPT_SHORTCUT_MOD 1021
#define OPT_NO_KEY_REPEAT 1022

bool
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
Expand All @@ -664,6 +668,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
{"no-control", no_argument, NULL, 'n'},
{"no-display", no_argument, NULL, 'N'},
{"no-mipmaps", no_argument, NULL, OPT_NO_MIPMAPS},
{"no-key-repeat", no_argument, NULL, OPT_NO_KEY_REPEAT},
{"port", required_argument, NULL, 'p'},
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
Expand Down Expand Up @@ -829,6 +834,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
case OPT_NO_MIPMAPS:
opts->mipmaps = false;
break;
case OPT_NO_KEY_REPEAT:
opts->forward_key_repeat = false;
break;
case OPT_CODEC_OPTIONS:
opts->codec_options = optarg;
break;
Expand Down
4 changes: 4 additions & 0 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ input_manager_init(struct input_manager *im,
const struct scrcpy_options *options)
{
im->control = options->control;
im->forward_key_repeat = options->forward_key_repeat;
im->prefer_text = options->prefer_text;

const struct sc_shortcut_mods *shortcut_mods = &options->shortcut_mods;
Expand Down Expand Up @@ -461,6 +462,9 @@ input_manager_process_key(struct input_manager *im,
}

if (event->repeat) {
if (!im->forward_key_repeat) {
return;
}
++im->repeat;
} else {
im->repeat = 0;
Expand Down
1 change: 1 addition & 0 deletions app/src/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct input_manager {
unsigned repeat;

bool control;
bool forward_key_repeat;
bool prefer_text;

struct {
Expand Down
2 changes: 2 additions & 0 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct scrcpy_options {
bool stay_awake;
bool force_adb_forward;
bool disable_screensaver;
bool forward_key_repeat;
};

#define SCRCPY_OPTIONS_DEFAULT { \
Expand Down Expand Up @@ -121,6 +122,7 @@ struct scrcpy_options {
.stay_awake = false, \
.force_adb_forward = false, \
.disable_screensaver = false, \
.forward_key_repeat = true, \
}

bool
Expand Down

0 comments on commit 84f1d9e

Please sign in to comment.