Created
June 10, 2024 08:52
-
-
Save plateaukao/989010a8745ca003ddd0813180cd7880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KeyEventsSender { | |
public static void sendKeyEvent(String keyCode) { | |
try { | |
Process process = Runtime.getRuntime().exec("su"); | |
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); | |
outputStream.writeBytes("input keyevent " + keyCode + "\n"); | |
outputStream.flush(); | |
outputStream.writeBytes("exit\n"); | |
outputStream.flush(); | |
process.waitFor(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment