Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard presses are being sent out too fast(repetititve) #109

Closed
wieuwzak opened this issue Mar 31, 2018 · 28 comments
Closed

Keyboard presses are being sent out too fast(repetititve) #109

wieuwzak opened this issue Mar 31, 2018 · 28 comments

Comments

@wieuwzak
Copy link

Hi,

When using chat apps through scrcpy, one enter key press seems to send multiple enter key presses.
For instance, when I press enter in whatsapp, my message gets sent and the typing bar emptied itself. But also tries to send out a message that contains no letters. This gives me an annoying toast that says I cant send blank messages. Happens almost on every enter press. Looks like it sends multiple enter presses while it should be one.

@rom1v
Copy link
Collaborator

rom1v commented Apr 2, 2018

one enter key press seems to send multiple enter key presses.

I am not able to reproduce for now.

@rom1v
Copy link
Collaborator

rom1v commented Apr 3, 2018

If you press enter in any text editor on your computer, does it sometimes generate several newlines?

What is your OS (Linux, Windows, macOS…)?

@EnderHDMC
Copy link

EnderHDMC commented Apr 9, 2018

You can test this in games. Minecraft is a good example. If you hold W, instead of it being one continuous keystroke, it seems to send it as many short keystrokes, this makes it impossible to walk properly. The character walks for a few milliseconds, stops, and repeats this until you let go of W.

I didn't get the same issue on Whatsapp though, just thought this would probably be a related issue.

System (from uname -a):
Linux DarkEnder 4.15.0-kali2-amd64 #1 SMP Debian 4.15.11-1kali1 (2018-03-21) x86_64 GNU/Linux

Phone (from Droid Info): Sony Xperia X Compact
Model: F5321
Build Number 34.3.A.0.252
OS Version: M MR1 (7.1.1)
SDK: 25

@rom1v
Copy link
Collaborator

rom1v commented Apr 9, 2018

OK. So the solution is probably to forward the repeat field of SDL_KeyboardEvent, and inject it on the device.

@wieuwzak
Copy link
Author

wieuwzak commented Apr 9, 2018

My keyboard functions as normal in all other situations. I have "press enter to send message" option enabled in Whatsapp. I just feel like we are missing a basic function where repetitive keystrokes aren't being issued too fast. For example when long pressing enter in a normal situation, there's a time limit before a keystroke is being noticed as repetitive. But when in scrcpy I feel like that time limit is non existent? Rom1v thank you for your solution and work!

@ghost
Copy link

ghost commented Jun 28, 2018

Same issue here. To me, It happens on Duolingo.

captura de pantalla

Any advance on this issue? Thanks in advance

@rom1v rom1v added the bug label Jun 28, 2018
@rom1v
Copy link
Collaborator

rom1v commented Oct 4, 2018

Could you test with v1.4 please? Maybe #87 fixes your problem as a side-effect.

@ghost
Copy link

ghost commented Oct 4, 2018

Tested with v1.4, and the issue now is typing latin characters like áãàâ or óôòõ. It duplicates the character with its correspondent without accents or tilde.

screenshot_scrcpy

@rom1v
Copy link
Collaborator

rom1v commented Oct 5, 2018

@maiconandsilva Thank you for your feedback.

the issue now is typing latin characters like áãàâ or óôòõ

The fact that these chars are duplicated is still the same issue: it seems that there is a problem in your Android version either to convert a String to a list of events, or the way the events generated are interpreted.

If you (or someone having a device with the same problem) can figure out if something is wrong with the result of charMap.getEvents(chars).

The fact that the accents or tilde are not added is a separate issue, and probably comes from your Android keyboard not supporting "diacritical dead key characters" (see Handle accented characters).

@Mehardeep
Copy link

SDL generates fake repeated keypresses if you hold a key long enough. This is used mostly for text input.
The original key press has .repeat == 0, and fake presses have .repeat == 1
SDL_KeyboardEvent *event
if(event->repeat ==0){
}

@rom1v
Copy link
Collaborator

rom1v commented Apr 9, 2020

Does it stlil happen on latest version?

@StephenW789
Copy link

@rom1v I think this issue still occurs. I tested on both the v1.12 and v1.14 in terms of typing into google docs, and if a key is held down long enough, it does seem to generate fake repeated keypresses (maybe that is where the lag comes from).

I think this is the issue I encountered in Minecraft as well. Once I hold down a key for an extended period of time, the character will continue moving for several seconds even after the key is released. It has nothing to do with the screen mirroring lag between computer and phone.

Is there anyway I can fix it/reduce performance issues?

@rom1v
Copy link
Collaborator

rom1v commented May 29, 2020

Could you test with this change:

diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java
index 349486c..9f1b69f 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java
@@ -164,7 +164,7 @@ public final class Device {
     }
 
     public boolean injectEvent(InputEvent event) {
-        return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
+        return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
     }
 
     public boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) {

or this one:

diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java
index 349486c..eb877e9 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java
@@ -164,7 +164,7 @@ public final class Device {
     }
 
     public boolean injectEvent(InputEvent event) {
-        return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
+        return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT);
     }
 
     public boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) {

@StephenW789
Copy link

@rom1v

I think I have found the correct file underhttps://github.com/Genymobile/scrcpy/blob/master/server/src/main/java/com/genymobile/scrcpy/Device.java .

In order to make the change, how can I alter the code on my local PC? Or should I push the code onto github?

@rom1v
Copy link
Collaborator

rom1v commented May 29, 2020

No, you must apply the changes and build locally.

Anyway, here is the server (to replace in v1.14) with WAIT_FOR_FINISH:

  • scrcpy-server
    SHA256: a9d56b4b8914ad949f5f191f01a983c6a43df0c88b7ba4973881017bf851c7f3

@StephenW789
Copy link

@rom1v I have tested it on google docs on v1.14

It seems like the words continue to lag during typing. Visually, after the changes, there is a difference in typing, but not much improvement.

For the file you suggested, did you provide the "WAIT_FOR_FINISH" or the "WAIT_FOR_RESULT"?

@StephenW789
Copy link

@rom1v May you also supply the server for v1.12 for both "WAIT_FOR_FINISH" and "WAIT_FOR_RESULT"? Perhaps its a combination of both the rendering GUI + the keyboard issue.

@rom1v
Copy link
Collaborator

rom1v commented May 29, 2020

No, that was just a quick test, I don't think it has any impact. And there is no rendering issue on v1.14 in #1441.

@StephenW789
Copy link

Since we already tested "WAIT_FOR_FINISH", would the "WAIT_FOR_RESULT" improve performance instead?

I took a look at the java code on github, and it seemed like most of these changes are simply constant values in the Java InputManager class. Do you think there is something else that's slowing this down?

@rom1v
Copy link
Collaborator

rom1v commented May 29, 2020

The slowdown is probably in the Android rom itself when we send too many events too quickly.

@StephenW789
Copy link

I see. Is there anyway this can be fixed? Or is this likely an issue on the android's part?

@rom1v
Copy link
Collaborator

rom1v commented May 29, 2020

I don't know. It greatly depends on the device. On my device I have no problem.

@StephenW789
Copy link

What is your device? Do you have any settings on?

@StephenW789
Copy link

I have a motog6, 2GB of RAM, are you using a newer model?

@StephenW789
Copy link

I tested this over wireless, thinking that it may be the data cable being slow, but the keyboard lag is still persistant.

Under the developer options for my phone, I also reduced all three animation scales, forced GPU rendering, force 4x MSAA, hoping that it would improve my phone's performance, but did not fix the keyboard lag.

@StephenW789
Copy link

I have noticed that when copy-pasting a long line of text in google docs, there is also a keyboard lag. Interestingly, the characters when pasted are typed out one by one on the display, rather than all at once.

@xeropresence
Copy link
Contributor

No, you must apply the changes and build locally.

Anyway, here is the server (to replace in v1.14) with WAIT_FOR_FINISH:

  • scrcpy-server
    SHA256: a9d56b4b8914ad949f5f191f01a983c6a43df0c88b7ba4973881017bf851c7f3

Having this issue on my device, moto x4 running havoc-os. Using this scrcpy-server did not seem to effect keyboard inputs, but did effect touch events. Touch events that were genereated by clicking and dragging the mouse were greatly slowed down.

@rom1v
Copy link
Collaborator

rom1v commented Oct 27, 2021

There is an option --no-key-repeat since v1.15.

@rom1v rom1v closed this as completed Oct 27, 2021
@rom1v rom1v mentioned this issue Jan 23, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants