WIP send several chars at once

This commit is contained in:
Romain Vimont 2020-11-09 21:39:47 +01:00
commit cd860bff81

View file

@ -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,15 +148,6 @@ public class Controller {
} }
private boolean injectChar(char c) { private boolean injectChar(char c) {
if (options.useADBKeyboard()) {
// Process latin keys the same way in order to provide same reaction speed.
Intent intent = new Intent();
intent.setAction("ADB_INPUT_CHARS");
int[] chars = {c};
intent.putExtra("chars", chars);
device.sendBroadcast(intent);
return true;
} else {
String decomposed = KeyComposition.decompose(c); String decomposed = KeyComposition.decompose(c);
char[] chars = decomposed != null ? decomposed.toCharArray() : new char[]{c}; char[] chars = decomposed != null ? decomposed.toCharArray() : new char[]{c};
KeyEvent[] events = charMap.getEvents(chars); KeyEvent[] events = charMap.getEvents(chars);
@ -172,11 +161,22 @@ public class Controller {
} }
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;