Skip to content

Commit

Permalink
Rename keycode injection method
Browse files Browse the repository at this point in the history
Make it explicit that it injects both "press" and "release" events.
  • Loading branch information
rom1v committed Apr 30, 2021
1 parent 9a7d351 commit 233f8e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void initPointers() {
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.
Expand Down Expand Up @@ -273,7 +273,7 @@ private boolean pressBackOrTurnScreenOn(int action) {
if (keepPowerModeOff) {
schedulePowerModeOff();
}
return device.injectKeycode(KeyEvent.KEYCODE_POWER);
return device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER);
}

private boolean setClipboard(String text, boolean paste) {
Expand All @@ -284,7 +284,7 @@ private boolean setClipboard(String text, boolean paste) {

// 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;
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ public boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState
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() {
Expand Down Expand Up @@ -272,7 +272,7 @@ public static boolean powerOffScreen(int displayId) {
if (!isScreenOn()) {
return true;
}
return injectKeycode(KeyEvent.KEYCODE_POWER, displayId);
return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, displayId);
}

/**
Expand Down

0 comments on commit 233f8e6

Please sign in to comment.