Skip to content

Display and control your Android device

Add --no-key-repeat cli option

xeropresence84f1d9e37502
diff --git a/README.md b/README.md
index b3a5c6b6..d875fd99 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/app/scrcpy.1 b/app/scrcpy.1
index 728d14fe..49fa78dc 100644
--- a/app/scrcpy.1
+++ b/app/scrcpy.1
@@ -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.
diff --git a/app/src/cli.c b/app/src/cli.c
index b75ab41a..c957b22f 100644
--- a/app/src/cli.c
+++ b/app/src/cli.c
@@ -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"
@@ -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[]) {
@@ -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},
@@ -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;
diff --git a/app/src/input_manager.c b/app/src/input_manager.c
index 3bf2282e..02dd9cb5 100644
--- a/app/src/input_manager.c
+++ b/app/src/input_manager.c
@@ -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;
@@ -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;
diff --git a/app/src/input_manager.h b/app/src/input_manager.h
index b3be6507..8811c457 100644
--- a/app/src/input_manager.h
+++ b/app/src/input_manager.h
@@ -23,6 +23,7 @@ struct input_manager {
unsigned repeat;
bool control;
+ bool forward_key_repeat;
bool prefer_text;
struct {
diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h
index 05af002f..86a2b57b 100644
--- a/app/src/scrcpy.h
+++ b/app/src/scrcpy.h
@@ -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 { \
@@ -121,6 +122,7 @@ struct scrcpy_options {
.stay_awake = false, \
.force_adb_forward = false, \
.disable_screensaver = false, \
+ .forward_key_repeat = true, \
}
bool