From 233f8e6cc4e84baaf3761ea61a60ba802aafeb88 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 30 Apr 2021 23:05:15 +0200 Subject: [PATCH] Rename keycode injection method Make it explicit that it injects both "press" and "release" events. --- .../src/main/java/com/genymobile/scrcpy/Controller.java | 6 +++--- server/src/main/java/com/genymobile/scrcpy/Device.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java index 3760bbd4..92986241 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java @@ -55,7 +55,7 @@ public class Controller { public void control() throws IOException { // on start, power on the device if (!Device.isScreenOn()) { - device.injectKeycode(KeyEvent.KEYCODE_POWER); + device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER); // dirty hack // After POWER is injected, the device is powered on asynchronously. @@ -273,7 +273,7 @@ public class Controller { if (keepPowerModeOff) { schedulePowerModeOff(); } - return device.injectKeycode(KeyEvent.KEYCODE_POWER); + return device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER); } private boolean setClipboard(String text, boolean paste) { @@ -284,7 +284,7 @@ public class Controller { // On Android >= 7, also press the PASTE key if requested if (paste && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && device.supportsInputEvents()) { - device.injectKeycode(KeyEvent.KEYCODE_PASTE); + device.pressReleaseKeycode(KeyEvent.KEYCODE_PASTE); } return ok; diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index 4374ffc5..3e71fe9c 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -191,12 +191,12 @@ public final class Device { return injectKeyEvent(action, keyCode, repeat, metaState, displayId); } - public static boolean injectKeycode(int keyCode, int displayId) { + public static boolean pressReleaseKeycode(int keyCode, int displayId) { return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0, displayId) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0, displayId); } - public boolean injectKeycode(int keyCode) { - return injectKeycode(keyCode, displayId); + public boolean pressReleaseKeycode(int keyCode) { + return pressReleaseKeycode(keyCode, displayId); } public static boolean isScreenOn() { @@ -272,7 +272,7 @@ public final class Device { if (!isScreenOn()) { return true; } - return injectKeycode(KeyEvent.KEYCODE_POWER, displayId); + return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, displayId); } /**