mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +00:00
WIP send several chars at once
This commit is contained in:
parent
160ae02b93
commit
cd860bff81
1 changed files with 22 additions and 22 deletions
|
@ -1,7 +1,5 @@
|
||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
@ -150,33 +148,35 @@ public class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean injectChar(char c) {
|
private boolean injectChar(char c) {
|
||||||
if (options.useADBKeyboard()) {
|
String decomposed = KeyComposition.decompose(c);
|
||||||
// Process latin keys the same way in order to provide same reaction speed.
|
char[] chars = decomposed != null ? decomposed.toCharArray() : new char[]{c};
|
||||||
Intent intent = new Intent();
|
KeyEvent[] events = charMap.getEvents(chars);
|
||||||
intent.setAction("ADB_INPUT_CHARS");
|
if (events == null) {
|
||||||
int[] chars = {c};
|
return false;
|
||||||
intent.putExtra("chars", chars);
|
}
|
||||||
device.sendBroadcast(intent);
|
for (KeyEvent event : events) {
|
||||||
return true;
|
if (!device.injectEvent(event)) {
|
||||||
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
for (KeyEvent event : events) {
|
|
||||||
if (!device.injectEvent(event)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int injectText(String text) {
|
private int injectText(String text) {
|
||||||
|
char[] chars = text.toCharArray();
|
||||||
|
if (options.useADBKeyboard()) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction("ADB_INPUT_CHARS");
|
||||||
|
int[] intChars = new int[chars.length];
|
||||||
|
for (int i = 0; i < chars.length; ++i) {
|
||||||
|
intChars[i] = chars[i];
|
||||||
|
}
|
||||||
|
intent.putExtra("chars", intChars);
|
||||||
|
device.sendBroadcast(intent);
|
||||||
|
return chars.length;
|
||||||
|
}
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
for (char c : text.toCharArray()) {
|
for (char c : chars) {
|
||||||
if (!injectChar(c)) {
|
if (!injectChar(c)) {
|
||||||
Ln.w("Could not inject char u+" + String.format("%04x", (int) c));
|
Ln.w("Could not inject char u+" + String.format("%04x", (int) c));
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue