mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-09-12 12:31:59 +00:00
Implement clipboard paste
Paste computer clipboard to the device on Ctrl+v. The other direction (pasting the device clipboard to the computer) is not implemented. It would require a communication channel from the device to the computer, other than the socket used by the video stream.
This commit is contained in:
parent
e4d64e8752
commit
e2a7abcd53
8 changed files with 62 additions and 19 deletions
|
@ -13,12 +13,12 @@ public class ControlEventReader {
|
|||
private static final int SCROLL_PAYLOAD_LENGTH = 16;
|
||||
private static final int COMMAND_PAYLOAD_LENGTH = 1;
|
||||
|
||||
private static final int MAX_TEXT_LENGTH = 32;
|
||||
private static final int TEXT_MAX_LENGTH = 256;
|
||||
private static final int RAW_BUFFER_SIZE = 128;
|
||||
|
||||
private final byte[] rawBuffer = new byte[RAW_BUFFER_SIZE];
|
||||
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
|
||||
private final byte[] textBuffer = new byte[MAX_TEXT_LENGTH];
|
||||
private final byte[] textBuffer = new byte[TEXT_MAX_LENGTH];
|
||||
|
||||
public ControlEventReader() {
|
||||
// invariant: the buffer is always in "get" mode
|
||||
|
|
|
@ -93,14 +93,12 @@ public class EventController {
|
|||
return injectKeyEvent(action, keycode, 0, metaState);
|
||||
}
|
||||
|
||||
private boolean injectText(String text) {
|
||||
return injectText(text, true);
|
||||
}
|
||||
|
||||
private boolean injectText(String text, boolean decomposeOnFailure) {
|
||||
KeyEvent[] events = charMap.getEvents(text.toCharArray());
|
||||
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 decomposeOnFailure ? injectDecomposition(text) : false;
|
||||
return false;
|
||||
}
|
||||
for (KeyEvent event : events) {
|
||||
if (!injectEvent(event)) {
|
||||
|
@ -110,10 +108,9 @@ public class EventController {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean injectDecomposition(String text) {
|
||||
private boolean injectText(String text) {
|
||||
for (char c : text.toCharArray()) {
|
||||
String composedText = KeyComposition.decompose(c);
|
||||
if (composedText == null || !injectText(composedText, false)) {
|
||||
if (!injectChar(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue