Fix clicking on clock every X times

This commit is contained in:
Bea 2024-08-05 20:50:03 +02:00
parent b038098c3c
commit 48f12a1640
5 changed files with 52 additions and 16 deletions

View File

@ -13,8 +13,6 @@ import java.util.Timer;
public class Main { public class Main {
private static final int LOOPS_BEFORE_CLICK = 5;
private static boolean running = true; private static boolean running = true;
private static final Logger LOGGER = LogManager.getLogger(Main.class); private static final Logger LOGGER = LogManager.getLogger(Main.class);

View File

@ -2,6 +2,7 @@ package wtf.beatrice.autosqueal.controls;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import wtf.beatrice.autosqueal.util.RunnerUtil;
import java.awt.*; import java.awt.*;
import java.security.SecureRandom; import java.security.SecureRandom;
@ -15,14 +16,12 @@ public class CursorMover extends TimerTask
private static final Logger LOGGER = LogManager.getLogger(CursorMover.class); private static final Logger LOGGER = LogManager.getLogger(CursorMover.class);
private final Random RANDOM; private final Random RANDOM;
private final int SCREEN_HEIGHT; private static final int LOOPS_BEFORE_CLICK = 5;
private final int SCREEN_WIDTH;
public CursorMover(int screenWidth, int screenHeight) { private int iteration = 0;
public CursorMover() {
RANDOM = new SecureRandom(); RANDOM = new SecureRandom();
this.SCREEN_WIDTH = screenWidth;
this.SCREEN_HEIGHT = screenHeight;
} }
@Override @Override
@ -33,13 +32,31 @@ public class CursorMover extends TimerTask
LOGGER.info("Starting coordinates: {}, {}", currentX, currentY); LOGGER.info("Starting coordinates: {}, {}", currentX, currentY);
int destX = RANDOM.nextInt(SCREEN_WIDTH); int destX;
int destY = RANDOM.nextInt(SCREEN_HEIGHT); int destY;
SingleStepMovementTask singleStepMovementTask;
if (iteration == LOOPS_BEFORE_CLICK) {
destX = RunnerUtil.SCREEN_WIDTH - 5;
destY = 5;
singleStepMovementTask = new SingleStepMovementTask(destX, destY, true);
iteration = 0;
} else {
destX = RANDOM.nextInt(RunnerUtil.SCREEN_WIDTH);
destY = RANDOM.nextInt(RunnerUtil.SCREEN_HEIGHT);
singleStepMovementTask = new SingleStepMovementTask(destX, destY, false);
iteration++;
}
LOGGER.info("Destination coordinates: {}, {}", destX, destY); LOGGER.info("Destination coordinates: {}, {}", destX, destY);
Timer timer = new Timer(); Timer timer = new Timer();
SingleStepMovementTask singleStepMovementTask = new SingleStepMovementTask(destX, destY);
timer.schedule(singleStepMovementTask, 0L, 2L); timer.schedule(singleStepMovementTask, 0L, 2L);
} }
} }

View File

@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.awt.*; import java.awt.*;
import java.awt.event.InputEvent;
import java.util.TimerTask; import java.util.TimerTask;
public class SingleStepMovementTask extends TimerTask { public class SingleStepMovementTask extends TimerTask {
@ -20,9 +21,12 @@ public class SingleStepMovementTask extends TimerTask {
float stepX = 1; float stepX = 1;
float stepY = 1; float stepY = 1;
boolean isRunning = true; boolean isRunning = true;
boolean click;
public SingleStepMovementTask(int destinationX, int destinationY) { public SingleStepMovementTask(int destinationX, int destinationY, boolean click) {
this.click = click;
currentX = MouseInfo.getPointerInfo().getLocation().x; currentX = MouseInfo.getPointerInfo().getLocation().x;
currentY = MouseInfo.getPointerInfo().getLocation().y; currentY = MouseInfo.getPointerInfo().getLocation().y;
@ -67,6 +71,24 @@ public class SingleStepMovementTask extends TimerTask {
} }
if(destX == Math.round(currentX) || destY == Math.round(currentY)) { if(destX == Math.round(currentX) || destY == Math.round(currentY)) {
if (click) {
try {
Thread.sleep(500);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep(200);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep(500);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep(200);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep(200);
} catch (InterruptedException e) {
LOGGER.error(e);
return;
}
}
LOGGER.info("Reached destination, stopping mover timer"); LOGGER.info("Reached destination, stopping mover timer");
LOGGER.info("Dest: [{}, {}], Curr: [{}, {}]", destX, destY, currentX, currentY); LOGGER.info("Dest: [{}, {}], Curr: [{}, {}]", destX, destY, currentX, currentY);
isRunning = false; isRunning = false;

View File

@ -67,7 +67,7 @@ public class MainWindow
CursorMoveListener cursorMoveListener = new CursorMoveListener(); CursorMoveListener cursorMoveListener = new CursorMoveListener();
TIMER_RUNNER.schedule(cursorMoveListener, 0L, 1000L); TIMER_RUNNER.schedule(cursorMoveListener, 0L, 1000L);
cursorMover = new CursorMover(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT); cursorMover = new CursorMover();
TIMER_RUNNER.schedule(cursorMover, 1000L, RunnerUtil.SECONDS_BETWEEN_MOVES * 1000L); TIMER_RUNNER.schedule(cursorMover, 1000L, RunnerUtil.SECONDS_BETWEEN_MOVES * 1000L);
button.setLabel("Stop"); button.setLabel("Stop");

View File

@ -4,10 +4,9 @@ import java.awt.*;
public class RunnerUtil { public class RunnerUtil {
public static final int SECONDS_BETWEEN_MOVES = 5; public static final int SECONDS_BETWEEN_MOVES = 10;
public static final int SCREEN_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height; public static final int SCREEN_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
public static final int SCREEN_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width; public static final int SCREEN_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
} }