mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 19:45:00 +00:00
Handle repeating keycodes
This commit is contained in:
parent
1e4ee547b5
commit
d297747469
6 changed files with 35 additions and 8 deletions
|
@ -43,7 +43,8 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||
buf[1] = msg->inject_keycode.action;
|
||||
buffer_write32be(&buf[2], msg->inject_keycode.keycode);
|
||||
buffer_write32be(&buf[6], msg->inject_keycode.metastate);
|
||||
return 10;
|
||||
buffer_write32be(&buf[10], msg->inject_keycode.repeat);
|
||||
return 14;
|
||||
case CONTROL_MSG_TYPE_INJECT_TEXT: {
|
||||
size_t len =
|
||||
write_string(msg->inject_text.text,
|
||||
|
|
|
@ -45,6 +45,7 @@ struct control_msg {
|
|||
enum android_keyevent_action action;
|
||||
enum android_keycode keycode;
|
||||
enum android_metastate metastate;
|
||||
int repeat;
|
||||
} inject_keycode;
|
||||
struct {
|
||||
char *text; // owned, to be freed by SDL_free()
|
||||
|
|
|
@ -232,9 +232,11 @@ input_manager_process_text_input(struct input_manager *im,
|
|||
}
|
||||
}
|
||||
|
||||
int repeatCounter[AKEYCODE_ALL_APPS];
|
||||
|
||||
static bool
|
||||
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to,
|
||||
bool prefer_text) {
|
||||
bool prefer_text, bool repeat) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||
|
||||
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
||||
|
@ -247,6 +249,21 @@ convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (to->inject_keycode.action == AKEY_EVENT_ACTION_DOWN && repeat)
|
||||
{
|
||||
repeatCounter[to->inject_keycode.keycode] = repeatCounter[to->inject_keycode.keycode] + 1;
|
||||
//LOGW("Setting repeat mode to %d %d",to->inject_keycode.keycode,to->inject_keycode.repeat );
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOGW("Clearing repeate for %d",to->inject_keycode.keycode );
|
||||
repeatCounter[to->inject_keycode.keycode] = 0;
|
||||
}
|
||||
|
||||
|
||||
to->inject_keycode.repeat = repeatCounter[to->inject_keycode.keycode];
|
||||
//LOGW("Current code for %d ======== %d",to->inject_keycode.keycode,to->inject_keycode.repeat );
|
||||
|
||||
to->inject_keycode.metastate = convert_meta_state(mod);
|
||||
|
||||
return true;
|
||||
|
@ -412,7 +429,7 @@ input_manager_process_key(struct input_manager *im,
|
|||
}
|
||||
|
||||
struct control_msg msg;
|
||||
if (convert_input_key(event, &msg, im->prefer_text)) {
|
||||
if (convert_input_key(event, &msg, im->prefer_text,event->repeat)) {
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'inject keycode'");
|
||||
}
|
||||
|
|
|
@ -31,16 +31,18 @@ public final class ControlMessage {
|
|||
private int hScroll;
|
||||
private int vScroll;
|
||||
private int flags;
|
||||
private int repeat;
|
||||
|
||||
private ControlMessage() {
|
||||
}
|
||||
|
||||
public static ControlMessage createInjectKeycode(int action, int keycode, int metaState) {
|
||||
public static ControlMessage createInjectKeycode(int action, int keycode, int metaState,int repeat) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_INJECT_KEYCODE;
|
||||
msg.action = action;
|
||||
msg.keycode = keycode;
|
||||
msg.metaState = metaState;
|
||||
msg.repeat = repeat;
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
@ -108,6 +110,10 @@ public final class ControlMessage {
|
|||
public int getMetaState() {
|
||||
return metaState;
|
||||
}
|
||||
|
||||
public int getRepeat() {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
public int getAction() {
|
||||
return action;
|
||||
|
|
|
@ -99,7 +99,8 @@ public class ControlMessageReader {
|
|||
int action = toUnsigned(buffer.get());
|
||||
int keycode = buffer.getInt();
|
||||
int metaState = buffer.getInt();
|
||||
return ControlMessage.createInjectKeycode(action, keycode, metaState);
|
||||
int repeat = buffer.getInt();
|
||||
return ControlMessage.createInjectKeycode(action, keycode, metaState,repeat);
|
||||
}
|
||||
|
||||
private String parseString() {
|
||||
|
|
|
@ -74,7 +74,8 @@ public class Controller {
|
|||
switch (msg.getType()) {
|
||||
case ControlMessage.TYPE_INJECT_KEYCODE:
|
||||
if (device.supportsInputEvents()) {
|
||||
injectKeycode(msg.getAction(), msg.getKeycode(), msg.getMetaState());
|
||||
//Ln.w("Unknown event type: " + msg.getRepeat());
|
||||
injectKeycode(msg.getAction(), msg.getKeycode(), msg.getMetaState(),msg.getRepeat());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TEXT:
|
||||
|
@ -130,8 +131,8 @@ public class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean injectKeycode(int action, int keycode, int metaState) {
|
||||
return device.injectKeyEvent(action, keycode, 0, metaState);
|
||||
private boolean injectKeycode(int action, int keycode, int metaState,int repeat) {
|
||||
return device.injectKeyEvent(action, keycode, repeat, metaState);
|
||||
}
|
||||
|
||||
private boolean injectChar(char c) {
|
||||
|
|
Loading…
Add table
Reference in a new issue