Skip to content

Commit

Permalink
Wait as the input time
Browse files Browse the repository at this point in the history
  • Loading branch information
aa889788 authored and zzyyyl committed Oct 18, 2023
1 parent c639ad2 commit 2b2f719
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/shxyke/MaaTouch/ControlMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -92,8 +92,8 @@ public Point getPoint() {
return point;
}

public long getMillis() {
return millis;
public long getTargetTimestamp() {
return targetTimestamp;
}

public int getMetaState() {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/shxyke/MaaTouch/ControlThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2b2f719

Please sign in to comment.