Using ADBKeyboard for injecting text.
This commit is contained in:
committed by
Romain Vimont
parent
576814bcec
commit
e970b4bda3
@@ -20,6 +20,7 @@ public class Controller {
|
||||
|
||||
private final Device device;
|
||||
private final DesktopConnection connection;
|
||||
private final Options options;
|
||||
private final DeviceMessageSender sender;
|
||||
|
||||
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
||||
@@ -31,9 +32,10 @@ public class Controller {
|
||||
|
||||
private boolean keepPowerModeOff;
|
||||
|
||||
public Controller(Device device, DesktopConnection connection) {
|
||||
public Controller(Device device, DesktopConnection connection, Options options) {
|
||||
this.device = device;
|
||||
this.connection = connection;
|
||||
this.options = options;
|
||||
initPointers();
|
||||
sender = new DeviceMessageSender(connection);
|
||||
}
|
||||
@@ -145,18 +147,28 @@ public class Controller {
|
||||
}
|
||||
|
||||
private boolean injectChar(char c) {
|
||||
String decomposed = KeyComposition.decompose(c);
|
||||
char[] chars = decomposed != null ? decomposed.toCharArray() : new char[]{c};
|
||||
KeyEvent[] events = charMap.getEvents(chars);
|
||||
if (events == null) {
|
||||
return false;
|
||||
}
|
||||
for (KeyEvent event : events) {
|
||||
if (!device.injectEvent(event)) {
|
||||
if (options.useADBKeyboard()) {
|
||||
// Process latin keys the same way in order to provide same reaction speed.
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("am broadcast -a ADB_INPUT_CHARS --eia chars " + String.valueOf((int) c));
|
||||
return process.waitFor() == 0;
|
||||
} catch (Throwable throwable) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
String decomposed = KeyComposition.decompose(c);
|
||||
char[] chars = decomposed != null ? decomposed.toCharArray() : new char[]{c};
|
||||
KeyEvent[] events = charMap.getEvents(chars);
|
||||
if (events == null) {
|
||||
return false;
|
||||
}
|
||||
for (KeyEvent event : events) {
|
||||
if (!device.injectEvent(event)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int injectText(String text) {
|
||||
|
||||
@@ -17,6 +17,7 @@ public class Options {
|
||||
private boolean stayAwake;
|
||||
private String codecOptions;
|
||||
private String encoderName;
|
||||
private boolean useADBKeyboard;
|
||||
|
||||
public Ln.Level getLogLevel() {
|
||||
return logLevel;
|
||||
@@ -129,4 +130,12 @@ public class Options {
|
||||
public void setEncoderName(String encoderName) {
|
||||
this.encoderName = encoderName;
|
||||
}
|
||||
|
||||
public boolean useADBKeyboard() {
|
||||
return useADBKeyboard;
|
||||
}
|
||||
|
||||
public void setUseADBKeyboard(boolean useADBKeyboard) {
|
||||
this.useADBKeyboard = useADBKeyboard;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class Server {
|
||||
options.getEncoderName());
|
||||
|
||||
if (options.getControl()) {
|
||||
final Controller controller = new Controller(device, connection);
|
||||
final Controller controller = new Controller(device, connection, options);
|
||||
|
||||
// asynchronous
|
||||
startController(controller);
|
||||
@@ -122,7 +122,7 @@ public final class Server {
|
||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||
}
|
||||
|
||||
final int expectedParameters = 15;
|
||||
final int expectedParameters = 16;
|
||||
if (args.length != expectedParameters) {
|
||||
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
|
||||
}
|
||||
@@ -172,6 +172,9 @@ public final class Server {
|
||||
String encoderName = "-".equals(args[14]) ? null : args[14];
|
||||
options.setEncoderName(encoderName);
|
||||
|
||||
boolean useADBKeyboard = Boolean.parseBoolean(args[15]);
|
||||
options.setUseADBKeyboard(useADBKeyboard);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user