mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-08 17:18:55 +00:00
Add option to turn device screen off
In addition to the shortcut (Ctrl+o) to turn the device screen off, add a command-line argument to turn it off on start.
This commit is contained in:
parent
7f07b13446
commit
8e66b33000
4 changed files with 35 additions and 6 deletions
|
@ -53,9 +53,21 @@ public class Controller {
|
|||
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void control() throws IOException {
|
||||
// on start, power on the device
|
||||
powerOn();
|
||||
if (!device.isScreenOn()) {
|
||||
injectKeycode(KeyEvent.KEYCODE_POWER);
|
||||
|
||||
// dirty hack
|
||||
// After POWER is injected, the device is powered on asynchronously.
|
||||
// To turn the device screen off while mirroring, the client will send a message that
|
||||
// would be handled before the device is actually powered on, so its effect would
|
||||
// be "canceled" once the device is turned back on.
|
||||
// Adding this delay prevents to handle the message before the device is actually
|
||||
// powered on.
|
||||
SystemClock.sleep(500);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
handleEvent();
|
||||
|
@ -182,10 +194,6 @@ public class Controller {
|
|||
return device.injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
||||
}
|
||||
|
||||
private boolean powerOn() {
|
||||
return device.isScreenOn() || injectKeycode(KeyEvent.KEYCODE_POWER);
|
||||
}
|
||||
|
||||
private boolean pressBackOrTurnScreenOn() {
|
||||
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||
return injectKeycode(keycode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue