-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ADBKeyboard for injecting text #1751
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ private boolean injectKeycode(int action, int keycode, int repeat, int metaState | |
} | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should send the broadcast programmatically (to avoid execute a new process and add latency for every letter). I guess this involves retrieving an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that method stable enough? I only have A9 devices and there is something made about activities in A10. I'm not Android developer though. |
||
} 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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some numbers don't exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these is right. 👍