From 2b2f71948603742bfd85a2e7098cf5d96f5c00de Mon Sep 17 00:00:00 2001 From: shxyke Date: Wed, 18 Oct 2023 13:36:24 +0800 Subject: [PATCH] Wait as the input time --- app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java | 8 ++++---- app/src/main/java/com/shxyke/MaaTouch/ControlThread.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java b/app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java index 5d0353c..98cb49b 100644 --- a/app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java +++ b/app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java @@ -17,7 +17,7 @@ public final class ControlMessage { private long pointerId; private float pressure; private Point point; - private long millis; + private long targetTimestamp; private int keycode; private int repeat; private int metaState; @@ -66,7 +66,7 @@ public static ControlMessage createTouchMoveEvent(long pointerId, Point point, f public static ControlMessage createWaitEvent(long milis) { ControlMessage msg = new ControlMessage(TYPE_EVENT_WAIT); - msg.millis = milis; + msg.targetTimestamp = milis + System.currentTimeMillis(); return msg; } @@ -92,8 +92,8 @@ public Point getPoint() { return point; } - public long getMillis() { - return millis; + public long getTargetTimestamp() { + return targetTimestamp; } public int getMetaState() { diff --git a/app/src/main/java/com/shxyke/MaaTouch/ControlThread.java b/app/src/main/java/com/shxyke/MaaTouch/ControlThread.java index 6a4b582..b3257e6 100644 --- a/app/src/main/java/com/shxyke/MaaTouch/ControlThread.java +++ b/app/src/main/java/com/shxyke/MaaTouch/ControlThread.java @@ -35,7 +35,8 @@ public void handleMessage(ControlMessage msg) { break; case ControlMessage.TYPE_EVENT_WAIT: try { - Thread.sleep(msg.getMillis()); + long sleepTime = msg.getTargetTimestamp() - System.currentTimeMillis(); + Thread.sleep(sleepTime > 0 ? sleepTime : 0); } catch (InterruptedException e) { e.printStackTrace(); }