Skip to content

Commit 84f1d9e

Browse files
xeropresencerom1v
authored andcommitted
Add --no-key-repeat cli option
Add an option to avoid forwarding repeated key events. PR #1623 <#1623> Refs #1013 <#1013> Signed-off-by: Romain Vimont <[email protected]>
1 parent 65d06a3 commit 84f1d9e

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,18 @@ scrcpy --prefer-text
558558
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
559559

560560

561+
#### Key repeat
562+
563+
By default, holding a key down generates repeated key events. This can cause
564+
performance problems in some games, where these events are useless anyway.
565+
566+
To avoid forwarding repeated key events:
567+
568+
```bash
569+
scrcpy --no-key-repeat
570+
```
571+
572+
561573
### File drop
562574

563575
#### Install APK

app/scrcpy.1

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ Do not display device (only when screen recording is enabled).
9696
.B \-\-no\-mipmaps
9797
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.
9898

99+
.TP
100+
.B \-\-no\-key\-repeat
101+
Do not forward repeated key events when a key is held down.
102+
99103
.TP
100104
.BI "\-p, \-\-port " port[:port]
101105
Set the TCP port (range) used by the client to listen.

app/src/cli.c

+8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ scrcpy_print_usage(const char *arg0) {
9292
" mipmaps are automatically generated to improve downscaling\n"
9393
" quality. This option disables the generation of mipmaps.\n"
9494
"\n"
95+
" --no-key-repeat\n"
96+
" Do not forward repeated key events when a key is held down.\n"
97+
"\n"
9598
" -p, --port port[:port]\n"
9699
" Set the TCP port (range) used by the client to listen.\n"
97100
" Default is %d:%d.\n"
@@ -642,6 +645,7 @@ guess_record_format(const char *filename) {
642645
#define OPT_FORCE_ADB_FORWARD 1019
643646
#define OPT_DISABLE_SCREENSAVER 1020
644647
#define OPT_SHORTCUT_MOD 1021
648+
#define OPT_NO_KEY_REPEAT 1022
645649

646650
bool
647651
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[]) {
664668
{"no-control", no_argument, NULL, 'n'},
665669
{"no-display", no_argument, NULL, 'N'},
666670
{"no-mipmaps", no_argument, NULL, OPT_NO_MIPMAPS},
671+
{"no-key-repeat", no_argument, NULL, OPT_NO_KEY_REPEAT},
667672
{"port", required_argument, NULL, 'p'},
668673
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
669674
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
@@ -829,6 +834,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
829834
case OPT_NO_MIPMAPS:
830835
opts->mipmaps = false;
831836
break;
837+
case OPT_NO_KEY_REPEAT:
838+
opts->forward_key_repeat = false;
839+
break;
832840
case OPT_CODEC_OPTIONS:
833841
opts->codec_options = optarg;
834842
break;

app/src/input_manager.c

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ input_manager_init(struct input_manager *im,
5858
const struct scrcpy_options *options)
5959
{
6060
im->control = options->control;
61+
im->forward_key_repeat = options->forward_key_repeat;
6162
im->prefer_text = options->prefer_text;
6263

6364
const struct sc_shortcut_mods *shortcut_mods = &options->shortcut_mods;
@@ -461,6 +462,9 @@ input_manager_process_key(struct input_manager *im,
461462
}
462463

463464
if (event->repeat) {
465+
if (!im->forward_key_repeat) {
466+
return;
467+
}
464468
++im->repeat;
465469
} else {
466470
im->repeat = 0;

app/src/input_manager.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct input_manager {
2323
unsigned repeat;
2424

2525
bool control;
26+
bool forward_key_repeat;
2627
bool prefer_text;
2728

2829
struct {

app/src/scrcpy.h

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct scrcpy_options {
7878
bool stay_awake;
7979
bool force_adb_forward;
8080
bool disable_screensaver;
81+
bool forward_key_repeat;
8182
};
8283

8384
#define SCRCPY_OPTIONS_DEFAULT { \
@@ -121,6 +122,7 @@ struct scrcpy_options {
121122
.stay_awake = false, \
122123
.force_adb_forward = false, \
123124
.disable_screensaver = false, \
125+
.forward_key_repeat = true, \
124126
}
125127

126128
bool

0 commit comments

Comments
 (0)