Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created June 10, 2024 08:52
Show Gist options
  • Save plateaukao/989010a8745ca003ddd0813180cd7880 to your computer and use it in GitHub Desktop.
Save plateaukao/989010a8745ca003ddd0813180cd7880 to your computer and use it in GitHub Desktop.
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