Compare commits
57 Commits
e4d429a88f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c0a1cfb04 | |||
| 550446c439 | |||
| fb9dee3560 | |||
| 5530fb6ae9 | |||
| 825e1aa700 | |||
| 6c8aa73f67 | |||
| f90ad4af5c | |||
| a93273252a | |||
| 56e2d4a6ad | |||
| 8606af095e | |||
| 55fdc93557 | |||
| f43f21e768 | |||
| 4f4fd21be1 | |||
| f1c846af37 | |||
| 9db0d86b31 | |||
| d57d021749 | |||
| 93eef9b53f | |||
| f5f976bc14 | |||
| d6654caafa | |||
| a770d3d0b5 | |||
| b002da349b | |||
| 4f9783004e | |||
| a0f959ed2f | |||
| e53dc862b6 | |||
| 8ab50d7e81 | |||
| 399db2b27c | |||
| 7ca9431fea | |||
| 86bc795fe4 | |||
| 41d414fb7e | |||
| 8b048d71ed | |||
| 059b445e01 | |||
| bc14aa40fe | |||
| 5b63e9cb29 | |||
| 19ca8a713b | |||
| c97a3038f2 | |||
| 8ef9ea9288 | |||
| bef4913447 | |||
| 4d2d3403d6 | |||
| 7cc01d9d29 | |||
| c3c1b99f1b | |||
| 9ad074bb51 | |||
| a6c43fd646 | |||
| ab1a0a753c | |||
| 3e4c490183 | |||
| 48f12a1640 | |||
| b038098c3c | |||
| 9c0b3290f7 | |||
| d55817f463 | |||
| 7567552c1a | |||
| 15bf2f80a1 | |||
| 46265e99b1 | |||
| d841288db7 | |||
| 593603aec2 | |||
| e3c708e49d | |||
| 06eac10bbf | |||
| 2e67f9b150 | |||
| 64bc9a4313 |
65
.drone.yml
Normal file
65
.drone.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
kind: pipeline
|
||||||
|
name: verify
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# test if it compiles correctly
|
||||||
|
- name: build
|
||||||
|
image: maven:3-eclipse-temurin-21
|
||||||
|
commands:
|
||||||
|
- mvn verify --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
||||||
|
|
||||||
|
# run unit tests
|
||||||
|
- name: test
|
||||||
|
image: maven:3-eclipse-temurin-21
|
||||||
|
commands:
|
||||||
|
- mvn test --no-transfer-progress -B -V
|
||||||
|
|
||||||
|
# run code analysis
|
||||||
|
- name: code-analysis
|
||||||
|
image: maven:3-eclipse-temurin-21
|
||||||
|
commands:
|
||||||
|
- mvn sonar:sonar --no-transfer-progress -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.host.url=$SONAR_INSTANCE_URL -Dsonar.token=$SONAR_LOGIN_KEY -B -V
|
||||||
|
environment:
|
||||||
|
SONAR_PROJECT_KEY:
|
||||||
|
from_secret: sonar_project_key
|
||||||
|
SONAR_INSTANCE_URL:
|
||||||
|
from_secret: sonar_instance_url
|
||||||
|
SONAR_LOGIN_KEY:
|
||||||
|
from_secret: sonar_login_key
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
kind: pipeline
|
||||||
|
name: deploy
|
||||||
|
type: docker
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- promote
|
||||||
|
target:
|
||||||
|
- production
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# skip all previous steps because they were already ran in the "build" phase; we don't need to re-analyze the code.
|
||||||
|
|
||||||
|
# upload to maven repository
|
||||||
|
- name: maven-deploy
|
||||||
|
image: maven:3-eclipse-temurin-21
|
||||||
|
commands:
|
||||||
|
- mvn deploy --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true -B -V -gs settings.xml -Dmaven.repo.username=$MAVEN_REPO_USERNAME -Dmaven.repo.password=$MAVEN_REPO_PASSWORD
|
||||||
|
environment:
|
||||||
|
MAVEN_REPO_USERNAME:
|
||||||
|
from_secret: maven_repo_username
|
||||||
|
MAVEN_REPO_PASSWORD:
|
||||||
|
from_secret: maven_repo_password
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
application-*.log
|
||||||
target/
|
target/
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
|
|||||||
47
pom.xml
47
pom.xml
@@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
<groupId>wtf.beatrice</groupId>
|
<groupId>wtf.beatrice</groupId>
|
||||||
<artifactId>autosqueal</artifactId>
|
<artifactId>autosqueal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.0.5-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -18,13 +18,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-api</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
<version>2.23.1</version>
|
<version>2.24.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.23.1</version>
|
<version>2.24.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -34,8 +34,26 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>nexus-releases</id>
|
||||||
|
<name>Nexus Releases Repository</name>
|
||||||
|
<url>https://nexus.beatrice.wtf/repository/maven-releases/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<name>Nexus Snapshots Repository</name>
|
||||||
|
<url>https://nexus.beatrice.wtf/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||||
|
<artifactId>sonar-maven-plugin</artifactId>
|
||||||
|
<version>5.0.0.4389</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
@@ -61,4 +79,23 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-nexus-releases</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/releases</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>sonatype-nexus-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
38
readme.md
Normal file
38
readme.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# [autosqueal](https://git.beatrice.wtf/Tools/autosqeal)
|
||||||
|
[](https://drone.beatrice.wtf/Tools/autosqeal)
|
||||||
|
[](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
[](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
[](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
[](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
[](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
|
||||||
|
|
||||||
|
|
||||||
|
*little java tool to automatically perform mouse actions*
|
||||||
|
|
||||||
|
## supported systems
|
||||||
|
| system | support |
|
||||||
|
|-----------|------------|
|
||||||
|
| macOS | ✅ complete |
|
||||||
|
| GNU/Linux | ⏳ planned |
|
||||||
|
| Windows | ⏳ planned |
|
||||||
|
|
||||||
|
## building
|
||||||
|
**required tools**
|
||||||
|
- java 21 sdk
|
||||||
|
- git
|
||||||
|
- maven
|
||||||
|
|
||||||
|
**build steps**
|
||||||
|
1. clone the official repository linked below using `git clone`.
|
||||||
|
2. `cd` into the directory and run `mvn clean package`.
|
||||||
|
3. you will find a runnable jar with dependencies in the `target/` folder.
|
||||||
|
4. run the built jar file with `java -jar target/autosqueal-*-dependencies.jar`.
|
||||||
|
|
||||||
|
## support
|
||||||
|
| category | info |
|
||||||
|
|---------------------|---------------------------------------------------------------|
|
||||||
|
| official repository | [gitea src](https://git.beatrice.wtf/Tools/autosqeal.git) |
|
||||||
|
| mirror repository | [github src](https://github.com/mind-overflow/autosqueal.git) |
|
||||||
|
| build status | [drone-ci](https://drone.beatrice.wtf/Tools/autosqeal) |
|
||||||
|
| dev email | [hello@beatrice.wtf](mailto:hello@beatrice.wtf) |
|
||||||
|
|
||||||
3
renovate.json
Normal file
3
renovate.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
|
}
|
||||||
20
settings.xml
Normal file
20
settings.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
|
||||||
|
|
||||||
|
<servers>
|
||||||
|
<server>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<username>${maven.repo.username}</username>
|
||||||
|
<password>${maven.repo.password}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>nexus-releases</id>
|
||||||
|
<username>${maven.repo.username}</username>
|
||||||
|
<password>${maven.repo.password}</password>
|
||||||
|
</server>
|
||||||
|
</servers>
|
||||||
|
|
||||||
|
</settings>
|
||||||
|
|
||||||
@@ -4,65 +4,19 @@ import com.github.kwhat.jnativehook.GlobalScreen;
|
|||||||
import com.github.kwhat.jnativehook.NativeHookException;
|
import com.github.kwhat.jnativehook.NativeHookException;
|
||||||
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.listener.KeyPressListener;
|
||||||
import java.awt.*;
|
import wtf.beatrice.autosqueal.ui.MainWindow;
|
||||||
import java.awt.event.InputEvent;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Timer;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final int LOOPS_BEFORE_CLICK = 5;
|
|
||||||
private static final int TIME_BETWEEN_MOVES = 5;
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(Main.class);
|
private static final Logger LOGGER = LogManager.getLogger(Main.class);
|
||||||
|
private static final MainWindow mainWindow = new MainWindow();
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, AWTException {
|
public static void main(String[] args) {
|
||||||
LOGGER.info("Hello world!");
|
LOGGER.info("Hello world!");
|
||||||
|
|
||||||
registerJNativeHook();
|
registerJNativeHook();
|
||||||
|
mainWindow.init();
|
||||||
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 Random();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
//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, 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerJNativeHook() {
|
private static void registerJNativeHook() {
|
||||||
@@ -80,16 +34,8 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startMover(int destX, int destY) throws InterruptedException {
|
public static MainWindow getMainWindow() {
|
||||||
Timer timer = new Timer();
|
return mainWindow;
|
||||||
CursorMover cursorMover = new CursorMover(destX, destY);
|
|
||||||
timer.schedule(cursorMover, 0L, 2L);
|
|
||||||
while (cursorMover.isRunning()) {
|
|
||||||
Thread.sleep(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.cancel();
|
|
||||||
|
|
||||||
Thread.sleep(TIME_BETWEEN_MOVES * 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package wtf.beatrice.autosqueal.controls;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class CursorMover extends TimerTask
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(CursorMover.class);
|
||||||
|
private final Random random;
|
||||||
|
|
||||||
|
private static final int LOOPS_BEFORE_CLICK = 5;
|
||||||
|
|
||||||
|
private int iteration = 0;
|
||||||
|
|
||||||
|
public CursorMover() {
|
||||||
|
random = new SecureRandom();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
int currentX = MouseInfo.getPointerInfo().getLocation().x;
|
||||||
|
int currentY = MouseInfo.getPointerInfo().getLocation().y;
|
||||||
|
|
||||||
|
LOGGER.info("Starting coordinates: {}, {}", currentX, currentY);
|
||||||
|
|
||||||
|
int destX;
|
||||||
|
int destY;
|
||||||
|
|
||||||
|
SingleStepMovementTask singleStepMovementTask;
|
||||||
|
|
||||||
|
if (iteration == LOOPS_BEFORE_CLICK) {
|
||||||
|
destX = RunnerUtil.SCREEN_WIDTH - 5;
|
||||||
|
destY = 5;
|
||||||
|
|
||||||
|
try {
|
||||||
|
singleStepMovementTask = new SingleStepMovementTask(destX, destY, true);
|
||||||
|
} catch (AWTException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
iteration = 0;
|
||||||
|
} else {
|
||||||
|
destX = random.nextInt(RunnerUtil.SCREEN_WIDTH);
|
||||||
|
destY = random.nextInt(RunnerUtil.SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
try {
|
||||||
|
singleStepMovementTask = new SingleStepMovementTask(destX, destY, false);
|
||||||
|
} catch (AWTException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
iteration++;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info("Destination coordinates: {}, {}", destX, destY);
|
||||||
|
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(singleStepMovementTask, 0L, 2L);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,32 @@
|
|||||||
package wtf.beatrice.autosqueal;
|
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 java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class CursorMover extends TimerTask {
|
public class SingleStepMovementTask extends TimerTask {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CursorMover.class);
|
private static final Logger LOGGER = LogManager.getLogger(SingleStepMovementTask.class);
|
||||||
|
|
||||||
final int destX, destY;
|
final int destX;
|
||||||
|
final int destY;
|
||||||
final Robot robot;
|
final Robot robot;
|
||||||
|
|
||||||
float currentX, currentY;
|
float currentX;
|
||||||
float stepX = 1, stepY = 1;
|
float currentY;
|
||||||
|
|
||||||
|
float stepX = 1;
|
||||||
|
float stepY = 1;
|
||||||
boolean isRunning = true;
|
boolean isRunning = true;
|
||||||
|
boolean click;
|
||||||
|
|
||||||
|
|
||||||
public CursorMover(int destinationX, int destinationY) {
|
public SingleStepMovementTask(int destinationX, int destinationY, boolean click) throws AWTException {
|
||||||
|
|
||||||
|
this.click = click;
|
||||||
|
|
||||||
currentX = MouseInfo.getPointerInfo().getLocation().x;
|
currentX = MouseInfo.getPointerInfo().getLocation().x;
|
||||||
currentY = MouseInfo.getPointerInfo().getLocation().y;
|
currentY = MouseInfo.getPointerInfo().getLocation().y;
|
||||||
@@ -26,7 +34,8 @@ public class CursorMover extends TimerTask {
|
|||||||
destX = destinationX;
|
destX = destinationX;
|
||||||
destY = destinationY;
|
destY = destinationY;
|
||||||
|
|
||||||
int lengthX, lengthY;
|
int lengthX;
|
||||||
|
int lengthY;
|
||||||
|
|
||||||
lengthX = Math.round(Math.abs(currentX - destX));
|
lengthX = Math.round(Math.abs(currentX - destX));
|
||||||
lengthY = Math.round(Math.abs(currentY - destY));
|
lengthY = Math.round(Math.abs(currentY - destY));
|
||||||
@@ -43,11 +52,7 @@ public class CursorMover extends TimerTask {
|
|||||||
LOGGER.info("Len: [{}, {}]", lengthX, lengthY);
|
LOGGER.info("Len: [{}, {}]", lengthX, lengthY);
|
||||||
LOGGER.info("Step: [{}, {}]", stepX, stepY);
|
LOGGER.info("Step: [{}, {}]", stepX, stepY);
|
||||||
|
|
||||||
try {
|
|
||||||
robot = new Robot();
|
robot = new Robot();
|
||||||
} catch (AWTException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +67,24 @@ public class CursorMover 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);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package wtf.beatrice.autosqueal;
|
package wtf.beatrice.autosqueal.listener;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -8,8 +8,9 @@ import java.util.TimerTask;
|
|||||||
|
|
||||||
public class CursorMoveListener extends TimerTask {
|
public class CursorMoveListener extends TimerTask {
|
||||||
|
|
||||||
private int oldX, oldY;
|
private int oldX;
|
||||||
private int newX, newY;
|
private int oldY;
|
||||||
|
|
||||||
private int loops;
|
private int loops;
|
||||||
private boolean isUserAway;
|
private boolean isUserAway;
|
||||||
|
|
||||||
@@ -24,8 +25,8 @@ public class CursorMoveListener extends TimerTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
newX = MouseInfo.getPointerInfo().getLocation().x;
|
int newX = MouseInfo.getPointerInfo().getLocation().x;
|
||||||
newY = MouseInfo.getPointerInfo().getLocation().y;
|
int newY = MouseInfo.getPointerInfo().getLocation().y;
|
||||||
|
|
||||||
if(newX != oldX || newY != oldY) {
|
if(newX != oldX || newY != oldY) {
|
||||||
// cursor has been moved
|
// cursor has been moved
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package wtf.beatrice.autosqueal;
|
package wtf.beatrice.autosqueal.listener;
|
||||||
|
|
||||||
import com.github.kwhat.jnativehook.GlobalScreen;
|
import com.github.kwhat.jnativehook.GlobalScreen;
|
||||||
import com.github.kwhat.jnativehook.NativeHookException;
|
import com.github.kwhat.jnativehook.NativeHookException;
|
||||||
@@ -6,6 +6,7 @@ import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
|
|||||||
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
|
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
|
||||||
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.Main;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,16 +14,18 @@ import java.util.List;
|
|||||||
public class KeyPressListener implements NativeKeyListener
|
public class KeyPressListener implements NativeKeyListener
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = LogManager.getLogger(KeyPressListener.class);
|
private static final Logger LOGGER = LogManager.getLogger(KeyPressListener.class);
|
||||||
private final static List<Integer> pressedKeysIds = new ArrayList<>();
|
private static final List<Integer> pressedKeysIds = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
public void nativeKeyPressed(NativeKeyEvent e) {
|
public void nativeKeyPressed(NativeKeyEvent e) {
|
||||||
LOGGER.info("Key Pressed: {}", NativeKeyEvent.getKeyText(e.getKeyCode()));
|
String key = NativeKeyEvent.getKeyText(e.getKeyCode());
|
||||||
|
LOGGER.info("Key Pressed: {}", key);
|
||||||
|
|
||||||
if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
|
if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
|
||||||
try {
|
try {
|
||||||
GlobalScreen.unregisterNativeHook();
|
GlobalScreen.unregisterNativeHook();
|
||||||
} catch (NativeHookException nativeHookException) {
|
} catch (NativeHookException nativeHookException) {
|
||||||
nativeHookException.printStackTrace();
|
LOGGER.error("Failed to unregister native hook", nativeHookException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +34,10 @@ public class KeyPressListener implements NativeKeyListener
|
|||||||
handlePressedKeys();
|
handlePressedKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void nativeKeyReleased(NativeKeyEvent e) {
|
public void nativeKeyReleased(NativeKeyEvent e) {
|
||||||
LOGGER.info("Key Released: {}", NativeKeyEvent.getKeyText(e.getKeyCode()));
|
String key = NativeKeyEvent.getKeyText(e.getKeyCode());
|
||||||
|
LOGGER.info("Key Released: {}", key);
|
||||||
|
|
||||||
pressedKeysIds.remove((Integer) e.getKeyCode());
|
pressedKeysIds.remove((Integer) e.getKeyCode());
|
||||||
|
|
||||||
@@ -44,13 +49,11 @@ public class KeyPressListener implements NativeKeyListener
|
|||||||
pressedKeysIds.contains(NativeKeyEvent.VC_CONTROL)) {
|
pressedKeysIds.contains(NativeKeyEvent.VC_CONTROL)) {
|
||||||
|
|
||||||
StringBuilder keys = new StringBuilder();
|
StringBuilder keys = new StringBuilder();
|
||||||
pressedKeysIds.forEach(keyCode -> {
|
pressedKeysIds.forEach(keyCode -> keys.append("[").append(NativeKeyEvent.getKeyText(keyCode)).append("]"));
|
||||||
keys.append("[").append(NativeKeyEvent.getKeyText(keyCode)).append("]");
|
|
||||||
});
|
|
||||||
|
|
||||||
LOGGER.warn("Received shutdown keystroke: {}", keys);
|
LOGGER.warn("Received shutdown keystroke: {}", keys);
|
||||||
|
|
||||||
System.exit(0);
|
Main.getMainWindow().toggleRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
137
src/main/java/wtf/beatrice/autosqueal/ui/MainWindow.java
Normal file
137
src/main/java/wtf/beatrice/autosqueal/ui/MainWindow.java
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
package wtf.beatrice.autosqueal.ui;
|
||||||
|
|
||||||
|
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import wtf.beatrice.autosqueal.controls.CursorMover;
|
||||||
|
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
||||||
|
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
||||||
|
import wtf.beatrice.autosqueal.util.SystemUtil;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
public class MainWindow
|
||||||
|
{
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
|
||||||
|
|
||||||
|
private static final int WINDOW_HEIGHT = 700;
|
||||||
|
private static final int WINDOW_WIDTH = 800;
|
||||||
|
|
||||||
|
private Timer timerRunner = new Timer();
|
||||||
|
private CursorMover cursorMover = new CursorMover();
|
||||||
|
private Button toggleButton;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
||||||
|
frame.setTitle("autosqueal");
|
||||||
|
frame.setResizable(false);
|
||||||
|
|
||||||
|
toggleButton = new Button();
|
||||||
|
toggleButton.setBounds(new Rectangle((WINDOW_WIDTH / 2) - 60, WINDOW_HEIGHT - 60, 120, 30));
|
||||||
|
toggleButton.addActionListener(e -> toggleRunning());
|
||||||
|
frame.add(toggleButton);
|
||||||
|
toggleRunning();
|
||||||
|
|
||||||
|
int bordersPx = 10;
|
||||||
|
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
|
||||||
|
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
|
||||||
|
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
|
||||||
|
JLabel imageLabel = new JLabel(new ImageIcon(getScreenCapture(rescaleWidth, rescaleHeight)));
|
||||||
|
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
|
||||||
|
frame.add(imageLabel);
|
||||||
|
|
||||||
|
Image preciseScreenshot = getPreciseScreenshot();
|
||||||
|
JLabel timestampLabel = new JLabel(new ImageIcon(preciseScreenshot));
|
||||||
|
timestampLabel.setBounds(new Rectangle(bordersPx, bordersPx + rescaleHeight + bordersPx, 100, 30));
|
||||||
|
frame.add(timestampLabel);
|
||||||
|
|
||||||
|
|
||||||
|
frame.setLayout(null);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image getScreenCapture(int rescaleWidth, int rescaleHeight) {
|
||||||
|
|
||||||
|
Image fullImage = getScreenCapture();
|
||||||
|
return fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getPreciseScreenshot() {
|
||||||
|
|
||||||
|
if(SystemUtil.getHostSystem().equals(SystemUtil.OperatingSystem.MAC_OS)) {
|
||||||
|
BufferedImage screenshot = getScreenCapture();
|
||||||
|
return screenshot.getSubimage(RunnerUtil.SCREEN_WIDTH - 100,0, 100, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getScreenCapture() {
|
||||||
|
try {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
return robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
|
||||||
|
} catch (AWTException e) {
|
||||||
|
LOGGER.error("Robot initialization error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getBufferedImage(Image img) {
|
||||||
|
if (img instanceof BufferedImage image)
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a buffered image with transparency
|
||||||
|
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
// Draw the image on to the buffered image
|
||||||
|
Graphics2D bGr = bimage.createGraphics();
|
||||||
|
bGr.drawImage(img, 0, 0, null);
|
||||||
|
bGr.dispose();
|
||||||
|
|
||||||
|
// Return the buffered image
|
||||||
|
return bimage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleRunning() {
|
||||||
|
|
||||||
|
String label;
|
||||||
|
|
||||||
|
if (cursorMover == null) {
|
||||||
|
timerRunner = new Timer();
|
||||||
|
CursorMoveListener cursorMoveListener = new CursorMoveListener();
|
||||||
|
timerRunner.schedule(cursorMoveListener, 0L, 1000L);
|
||||||
|
|
||||||
|
cursorMover = new CursorMover();
|
||||||
|
timerRunner.schedule(cursorMover, 1000L, RunnerUtil.SECONDS_BETWEEN_MOVES * 1000L);
|
||||||
|
|
||||||
|
label = "Stop [" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_CONTROL) +
|
||||||
|
"][" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_ALT) +
|
||||||
|
"]";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timerRunner.cancel();
|
||||||
|
|
||||||
|
cursorMover = null;
|
||||||
|
|
||||||
|
label = "Start [" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_CONTROL) +
|
||||||
|
"][" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_ALT) +
|
||||||
|
"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleButton.setLabel(label);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
src/main/java/wtf/beatrice/autosqueal/util/RunnerUtil.java
Normal file
16
src/main/java/wtf/beatrice/autosqueal/util/RunnerUtil.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package wtf.beatrice.autosqueal.util;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class RunnerUtil {
|
||||||
|
|
||||||
|
private RunnerUtil() {
|
||||||
|
throw new AssertionError("The RunnerUtil class is not intended to be instantiated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int SECONDS_BETWEEN_MOVES = 10;
|
||||||
|
|
||||||
|
public static final int SCREEN_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
|
||||||
|
public static final int SCREEN_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
|
||||||
|
|
||||||
|
}
|
||||||
26
src/main/java/wtf/beatrice/autosqueal/util/SystemUtil.java
Normal file
26
src/main/java/wtf/beatrice/autosqueal/util/SystemUtil.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package wtf.beatrice.autosqueal.util;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class SystemUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
public static OperatingSystem getHostSystem() {
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
|
||||||
|
if (osName.contains("win")) {
|
||||||
|
return OperatingSystem.WINDOWS;
|
||||||
|
} else if (osName.contains("nix") ||
|
||||||
|
osName.contains("nux") ||
|
||||||
|
osName.contains("aix")) {
|
||||||
|
return OperatingSystem.LINUX;
|
||||||
|
} else if (osName.contains("mac")) {
|
||||||
|
return OperatingSystem.MAC_OS;
|
||||||
|
} else {
|
||||||
|
return OperatingSystem.UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OperatingSystem {
|
||||||
|
WINDOWS, LINUX, MAC_OS, UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,6 @@
|
|||||||
<Console name="ConsoleAppender" target="SYSTEM_OUT">
|
<Console name="ConsoleAppender" target="SYSTEM_OUT">
|
||||||
<PatternLayout pattern="[%d{HH:mm:ss.SSS}] [%t] %-4level | %logger{36} - %msg%n" />
|
<PatternLayout pattern="[%d{HH:mm:ss.SSS}] [%t] %-4level | %logger{36} - %msg%n" />
|
||||||
</Console>
|
</Console>
|
||||||
<File name="FileAppender" fileName="application-${date:yyyyMMdd}.log" immediateFlush="false" append="true">
|
|
||||||
<PatternLayout pattern="[%d{yyy-MM-dd HH:mm:ss.SSS}] [%t] %-4level | %logger{36} - %msg%n"/>
|
|
||||||
</File>
|
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="debug">
|
<Root level="debug">
|
||||||
|
|||||||
Reference in New Issue
Block a user