Refactor packages and add GUI with start button
continuous-integration/drone/push Build is passing

This commit is contained in:
bea
2024-08-05 20:39:14 +02:00
parent 9c0b3290f7
commit b038098c3c
7 changed files with 154 additions and 65 deletions
@@ -4,69 +4,28 @@ import com.github.kwhat.jnativehook.GlobalScreen;
import com.github.kwhat.jnativehook.NativeHookException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import wtf.beatrice.autosqueal.util.RunnerUtil;
import wtf.beatrice.autosqueal.listener.KeyPressListener;
import wtf.beatrice.autosqueal.ui.MainWindow;
import java.awt.*;
import java.awt.event.InputEvent;
import java.security.SecureRandom;
import java.util.Random;
import java.util.Timer;
public class Main {
private static final int LOOPS_BEFORE_CLICK = 5;
private static final int TIME_BETWEEN_MOVES = 5;
private static boolean running = true;
private static final Logger LOGGER = LogManager.getLogger(Main.class);
public static void main(String[] args) throws InterruptedException, AWTException {
public static void main(String[] args) {
LOGGER.info("Hello world!");
registerJNativeHook();
Timer timer = new Timer();
CursorMoveListener cursorMoveListener = new CursorMoveListener();
timer.schedule(cursorMoveListener, 0L, 1000L);
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
Random random = new SecureRandom();
while (running) {
//if(!cursorMoveListener.isUserAway()) continue;
for(int i = 0; i < LOOPS_BEFORE_CLICK; i++) {
int currentX = MouseInfo.getPointerInfo().getLocation().x;
int currentY = MouseInfo.getPointerInfo().getLocation().y;
LOGGER.info("Starting coordinates: {}, {}", currentX, currentY);
int randomX;
int randomY;
randomX = random.nextInt(width);
randomY = random.nextInt(height);
LOGGER.info("Destination coordinates: {}, {}", randomX, randomY);
startMover(randomX, randomY);
}
startMover(width - 5, 5);
Robot robot = new Robot();
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);
}
MainWindow mainWindow = new MainWindow();
mainWindow.init();
}
private static void registerJNativeHook() {
@@ -84,16 +43,4 @@ public class Main {
}
}
private static void startMover(int destX, int destY) throws InterruptedException {
Timer timer = new Timer();
CursorMover cursorMover = new CursorMover(destX, destY);
timer.schedule(cursorMover, 0L, 2L);
while (cursorMover.isRunning()) {
Thread.sleep(200);
}
timer.cancel();
Thread.sleep(TIME_BETWEEN_MOVES * 1000L);
}
}