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

Press Any Key to Continue... only accepts one key in console version #1757

Closed
2 tasks done
dieKatze88 opened this issue Sep 12, 2020 · 9 comments
Closed
2 tasks done

Comments

@dieKatze88
Copy link

dieKatze88 commented Sep 12, 2020

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Windows 10 1903
  • scrcpy version: 1.16
  • installation method: Windows Release, Unzipped to folder
  • device model: Motorola Z4
  • Android version: 10

Describe the bug
If you are using the console version, any time it says "Press any key to continue..." The console only accepts return to dismiss.

D:\scrcopy>scrcpy.exe -Sw
INFO: scrcpy 1.16 https://github.com/Genymobile/scrcpy
adb: error: failed to get feature set: no devices/emulators found
ERROR: "adb push" returned with value 1
Press any key to continue...

Pressing any other key other than Return does not have the intended result of dismissing the program.

@MatthewBerk
Copy link

Hello, I am new to contributing to open-source projects.

While looking through the code, I found that message here

fprintf(stderr, "Press any key to continue...\n");

followed by this code
getchar();

From experimenting on a simple C application, getchar() requires pressing ENTER/RETURN key to continue the program.
If you want any key press to continue the program, I found getch() provides that functionality. Requires importing conio.h header file.

https://www.geeksforgeeks.org/getch-function-in-c-with-examples/

@dieKatze88
Copy link
Author

The fun thing about this issue is there's actually two ways to fix it.

Either the above suggestion to change how a character is read from the console, or changing the language of the message, to be specific to pressing Return.

I'm not going to pretend to know which one is better for this error, because this isn't my project. I just spotted an issue in a program I found useful. If it were me, I would fix the code so it accepted any key, but scrcpy is probably more of a development tool to most users, where as I am a filthy casual using it to play Fire Emblem Heroes faster because I don't write android apps anymore. Seeing the errors might be more worth it to those users, so changing the language of the message might be more appropriate for this application. I honestly don't know and I'm not 100% up to the pulse of how this application is usually used.

@rom1v
Copy link
Collaborator

rom1v commented Sep 13, 2020

This message is just a workaround to pause in case of error on Windows, so that the console does not immediately close before having time to read the errors (140b1ef).

In practice, we don't care if we can quit with any key or just Enter. Since stdin is line-buffered, getchar() will return after a new line (by pressing Enter).

Since getch() is not standard, I'd prefer changing the text (even if the message is printed only on Windows).

@dieKatze88
Copy link
Author

The only other suggestion I could have is ditching the pause entirely on Windows, because this is always an option.

scrcpy-omgineedthat.cmd

scrcpy.exe
pause

@MatthewBerk
Copy link

Changing the text may be best since in this scenario, just want to give user control when program dismisses.

Just wanted to provide a solution in case wanted to stick with the "Press any key to continue".

rom1v pushed a commit that referenced this issue Oct 1, 2020
The message said "Press any key to continue...", whereas only
Enter/Return is accepted.

PR #1783 <#1783>
Fixes #1757 <#1757>

Reviewed-by: Yu-Chen Lin <[email protected]>
Signed-off-by: Romain Vimont <[email protected]>
@rom1v
Copy link
Collaborator

rom1v commented Oct 1, 2020

Fixed by #1783.

@rom1v rom1v closed this as completed Oct 1, 2020
@bvpranu97
Copy link

If you want your program to run after clicking any key to contitue to execute set of instructions then use getch in your windows system. First include conio.h header file and then call getch(); function.
Reference: https://scholarsoul.com/getch-in-c/

@saif822
Copy link

saif822 commented May 4, 2022

Hi Rom
I'm facing a problem in scrcpy
I have redmi10 pro , and when I run the scrcpy it works for just 2 seconds and disconnected abruptly
Have tried many time but facing same
Here's what I get
Microsoft Windows [Version 10.0.22000.613]
(c) Microsoft Corporation. All rights reserved.

C:\Users\muhammad suhail\Downloads\adb\platform-tools_r33.0.1-windows\platform-tools>scrcpy.exe
scrcpy 1.24 https://github.com/Genymobile/scrcpy
C:\Users\muhammad suhail\Downloads\adb\platform-tools_r33.... file pushed, 0 skipped. 40.0 MB/s (41159 bytes in 0.001s)
[server] INFO: Device: Xiaomi M2101K6P (Android 12)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2400
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3535)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:152)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
at com.genymobile.scrcpy.Server.main(Server.java:335)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:363)

C:\Users\muhammad suhail\Downloads\adb\platform-tools_r33.0.1-windows\platform-tools>C:\Users\muhammad suhail\Downloads\adb\platform-tools_r33.0.1-windows\platform-toolsC:\Users\muhammad suhail\Downloads\adb\platform-tools_r33.0.1-windows\platform-tools

@rom1v
Copy link
Collaborator

rom1v commented May 4, 2022

[server] ERROR: Encoding error: java.lang.IllegalStateException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]

#3051

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants