Compare commits
20 Commits
3e4c490183
...
inactivity
| Author | SHA1 | Date | |
|---|---|---|---|
| 35c705222b | |||
| 8ab50d7e81 | |||
| 399db2b27c | |||
| 7ca9431fea | |||
| 86bc795fe4 | |||
| 41d414fb7e | |||
| 8b048d71ed | |||
| 059b445e01 | |||
| bc14aa40fe | |||
| 5b63e9cb29 | |||
| 19ca8a713b | |||
| c97a3038f2 | |||
| 8ef9ea9288 | |||
| bef4913447 | |||
| 4d2d3403d6 | |||
| 7cc01d9d29 | |||
| c3c1b99f1b | |||
| 9ad074bb51 | |||
| a6c43fd646 | |||
| ab1a0a753c |
21
pom.xml
21
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<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>17</maven.compiler.source>
|
||||||
@@ -61,4 +61,23 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-nexus-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>sonatype-nexus-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
34
readme.md
34
readme.md
@@ -1,6 +1,38 @@
|
|||||||
# autosqueal
|
# [autosqueal](https://git.beatrice.wtf/Tools/autosqeal)
|
||||||
[](https://drone.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)
|
||||||
[](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 | ✅ **full** |
|
||||||
|
| Windows | 🟠 limited |
|
||||||
|
| GNU/Linux | 🟠 limited |
|
||||||
|
|
||||||
|
## building
|
||||||
|
**required tools**
|
||||||
|
- java 17 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) |
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,26 @@ 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.util.RunnerUtil;
|
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
||||||
import wtf.beatrice.autosqueal.listener.KeyPressListener;
|
import wtf.beatrice.autosqueal.listener.KeyPressListener;
|
||||||
import wtf.beatrice.autosqueal.ui.MainWindow;
|
import wtf.beatrice.autosqueal.ui.MainWindow;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static boolean running = true;
|
|
||||||
|
|
||||||
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) {
|
public static void main(String[] args) {
|
||||||
LOGGER.info("Hello world!");
|
LOGGER.info("Hello world!");
|
||||||
|
|
||||||
registerJNativeHook();
|
registerJNativeHook();
|
||||||
|
|
||||||
MainWindow mainWindow = new MainWindow();
|
|
||||||
mainWindow.init();
|
mainWindow.init();
|
||||||
|
|
||||||
|
Timer timerRunner = new Timer();
|
||||||
|
CursorMoveListener cursorMoveListener = new CursorMoveListener();
|
||||||
|
timerRunner.schedule(cursorMoveListener, 0L, 1000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerJNativeHook() {
|
private static void registerJNativeHook() {
|
||||||
@@ -41,4 +41,8 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MainWindow getMainWindow() {
|
||||||
|
return mainWindow;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,16 @@ 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 SingleStepMovementTask singleStepMovementTask;
|
||||||
|
|
||||||
private static final int LOOPS_BEFORE_CLICK = 5;
|
private static final int LOOPS_BEFORE_CLICK = 5;
|
||||||
|
|
||||||
private int iteration = 0;
|
private int iteration = 0;
|
||||||
|
|
||||||
public CursorMover() {
|
public CursorMover() {
|
||||||
RANDOM = new SecureRandom();
|
random = new SecureRandom();
|
||||||
|
singleStepMovementTask = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,20 +37,28 @@ public class CursorMover extends TimerTask
|
|||||||
int destX;
|
int destX;
|
||||||
int destY;
|
int destY;
|
||||||
|
|
||||||
SingleStepMovementTask singleStepMovementTask;
|
|
||||||
|
|
||||||
if (iteration == LOOPS_BEFORE_CLICK) {
|
if (iteration == LOOPS_BEFORE_CLICK) {
|
||||||
destX = RunnerUtil.SCREEN_WIDTH - 5;
|
destX = RunnerUtil.SCREEN_WIDTH - 5;
|
||||||
destY = 5;
|
destY = 5;
|
||||||
|
|
||||||
singleStepMovementTask = new SingleStepMovementTask(destX, destY, true);
|
try {
|
||||||
|
singleStepMovementTask = new SingleStepMovementTask(destX, destY, true);
|
||||||
|
} catch (AWTException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
iteration = 0;
|
iteration = 0;
|
||||||
} else {
|
} else {
|
||||||
destX = RANDOM.nextInt(RunnerUtil.SCREEN_WIDTH);
|
destX = random.nextInt(RunnerUtil.SCREEN_WIDTH);
|
||||||
destY = RANDOM.nextInt(RunnerUtil.SCREEN_HEIGHT);
|
destY = random.nextInt(RunnerUtil.SCREEN_HEIGHT);
|
||||||
|
|
||||||
singleStepMovementTask = new SingleStepMovementTask(destX, destY, false);
|
try {
|
||||||
|
singleStepMovementTask = new SingleStepMovementTask(destX, destY, false);
|
||||||
|
} catch (AWTException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
iteration++;
|
iteration++;
|
||||||
}
|
}
|
||||||
@@ -57,6 +67,11 @@ public class CursorMover extends TimerTask
|
|||||||
|
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
timer.schedule(singleStepMovementTask, 0L, 2L);
|
timer.schedule(singleStepMovementTask, 0L, 2L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
if (singleStepMovementTask == null) return false;
|
||||||
|
|
||||||
|
return singleStepMovementTask.isRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ public class SingleStepMovementTask extends TimerTask {
|
|||||||
|
|
||||||
float stepX = 1;
|
float stepX = 1;
|
||||||
float stepY = 1;
|
float stepY = 1;
|
||||||
boolean isRunning = true;
|
private boolean isRunning = true;
|
||||||
boolean click;
|
boolean click;
|
||||||
|
|
||||||
|
|
||||||
public SingleStepMovementTask(int destinationX, int destinationY, boolean click) {
|
public SingleStepMovementTask(int destinationX, int destinationY, boolean click) throws AWTException {
|
||||||
|
|
||||||
this.click = click;
|
this.click = click;
|
||||||
|
|
||||||
@@ -52,11 +52,7 @@ public class SingleStepMovementTask 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +81,7 @@ public class SingleStepMovementTask extends TimerTask {
|
|||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
return;
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ 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;
|
||||||
|
import wtf.beatrice.autosqueal.Main;
|
||||||
|
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@@ -11,9 +13,6 @@ public class CursorMoveListener extends TimerTask {
|
|||||||
private int oldX;
|
private int oldX;
|
||||||
private int oldY;
|
private int oldY;
|
||||||
|
|
||||||
private int newX;
|
|
||||||
private int newY;
|
|
||||||
|
|
||||||
private int loops;
|
private int loops;
|
||||||
private boolean isUserAway;
|
private boolean isUserAway;
|
||||||
|
|
||||||
@@ -28,22 +27,25 @@ public class CursorMoveListener extends TimerTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
newX = MouseInfo.getPointerInfo().getLocation().x;
|
if(RunnerUtil.isSquealing()) return;
|
||||||
newY = MouseInfo.getPointerInfo().getLocation().y;
|
|
||||||
|
int newX = MouseInfo.getPointerInfo().getLocation().x;
|
||||||
|
int newY = MouseInfo.getPointerInfo().getLocation().y;
|
||||||
|
|
||||||
if(newX != oldX || newY != oldY) {
|
if(newX != oldX || newY != oldY) {
|
||||||
// cursor has been moved
|
// cursor has been moved
|
||||||
loops = 0;
|
loops = 0;
|
||||||
LOGGER.info("User is no longer away!");
|
LOGGER.info("User is no longer away!");
|
||||||
} else {
|
} else {
|
||||||
if (loops < 30) {
|
if (loops < 10) {
|
||||||
loops++;
|
loops++;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("User is away!");
|
LOGGER.info("User is away!");
|
||||||
|
Main.getMainWindow().toggleRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isUserAway = loops >= 30;
|
isUserAway = loops >= 10;
|
||||||
|
|
||||||
oldX = newX;
|
oldX = newX;
|
||||||
oldY = newY;
|
oldY = newY;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -50,7 +51,7 @@ public class KeyPressListener implements NativeKeyListener
|
|||||||
|
|
||||||
LOGGER.warn("Received shutdown keystroke: {}", keys);
|
LOGGER.warn("Received shutdown keystroke: {}", keys);
|
||||||
|
|
||||||
System.exit(0);
|
Main.getMainWindow().toggleRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package wtf.beatrice.autosqueal.ui;
|
package wtf.beatrice.autosqueal.ui;
|
||||||
|
|
||||||
|
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
|
||||||
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.controls.CursorMover;
|
import wtf.beatrice.autosqueal.controls.CursorMover;
|
||||||
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
|
||||||
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
import wtf.beatrice.autosqueal.util.RunnerUtil;
|
||||||
|
import wtf.beatrice.autosqueal.util.SystemUtil;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
@@ -16,69 +17,126 @@ public class MainWindow
|
|||||||
{
|
{
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
|
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
|
||||||
|
|
||||||
private static final int WINDOW_HEIGHT = 600;
|
private static final int WINDOW_HEIGHT = 700;
|
||||||
private static final int WINDOW_WIDTH = 800;
|
private static final int WINDOW_WIDTH = 800;
|
||||||
|
|
||||||
private final Timer TIMER_RUNNER = new Timer();
|
private Timer timerRunner = new Timer();
|
||||||
|
private CursorMover cursorMover = new CursorMover();
|
||||||
private CursorMover cursorMover = null;
|
private Button toggleButton;
|
||||||
|
|
||||||
|
|
||||||
public MainWindow() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
frame.setSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
|
||||||
|
frame.setTitle("autosqueal");
|
||||||
|
frame.setResizable(false);
|
||||||
|
|
||||||
Button toggleButton = new Button("Start");
|
toggleButton = new Button();
|
||||||
toggleButton.setBounds(new Rectangle((WINDOW_WIDTH / 2) - 40, WINDOW_HEIGHT - 60, 80, 30));
|
toggleButton.setBounds(new Rectangle((WINDOW_WIDTH / 2) - 60, WINDOW_HEIGHT - 60, 120, 30));
|
||||||
toggleButton.addActionListener(e -> toggleRunning(toggleButton));
|
toggleButton.addActionListener(e -> toggleRunning());
|
||||||
frame.add(toggleButton);
|
frame.add(toggleButton);
|
||||||
|
toggleRunning();
|
||||||
|
|
||||||
int bordersPx = 10;
|
int bordersPx = 10;
|
||||||
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
|
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
|
||||||
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
|
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
|
||||||
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
|
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
|
||||||
JLabel imageLabel = new JLabel(getScreenCapture(rescaleWidth, rescaleHeight));
|
JLabel imageLabel = new JLabel(new ImageIcon(getScreenCapture(rescaleWidth, rescaleHeight)));
|
||||||
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
|
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
|
||||||
frame.add(imageLabel);
|
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.setLayout(null);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageIcon getScreenCapture(int rescaleWidth, int rescaleHeight) {
|
private Image getScreenCapture(int rescaleWidth, int rescaleHeight) {
|
||||||
|
|
||||||
try {
|
Image fullImage = getScreenCapture();
|
||||||
Robot robot = new Robot();
|
return fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
|
||||||
BufferedImage fullImage = robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
|
|
||||||
Image image = fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
|
|
||||||
return new ImageIcon(image);
|
|
||||||
} catch (AWTException e) {
|
|
||||||
LOGGER.error("Robot initialization error", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleRunning(Button button) {
|
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) {
|
if (cursorMover == null) {
|
||||||
CursorMoveListener cursorMoveListener = new CursorMoveListener();
|
timerRunner = new Timer();
|
||||||
TIMER_RUNNER.schedule(cursorMoveListener, 0L, 1000L);
|
|
||||||
|
|
||||||
cursorMover = new CursorMover();
|
cursorMover = new CursorMover();
|
||||||
TIMER_RUNNER.schedule(cursorMover, 1000L, RunnerUtil.SECONDS_BETWEEN_MOVES * 1000L);
|
timerRunner.schedule(cursorMover, 1000L, RunnerUtil.SECONDS_BETWEEN_MOVES * 1000L);
|
||||||
|
|
||||||
button.setLabel("Stop");
|
label = "Stop [" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_CONTROL) +
|
||||||
|
"][" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_ALT) +
|
||||||
|
"]";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TIMER_RUNNER.cancel();
|
timerRunner.cancel();
|
||||||
|
|
||||||
cursorMover = null;
|
cursorMover = null;
|
||||||
|
|
||||||
button.setLabel("Start");
|
label = "Start [" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_CONTROL) +
|
||||||
|
"][" +
|
||||||
|
NativeKeyEvent.getKeyText(NativeKeyEvent.VC_ALT) +
|
||||||
|
"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleButton.setLabel(label);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public boolean isRunning() {
|
||||||
|
if (cursorMover == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return cursorMover.isRunning();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
package wtf.beatrice.autosqueal.util;
|
package wtf.beatrice.autosqueal.util;
|
||||||
|
|
||||||
|
import wtf.beatrice.autosqueal.Main;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class RunnerUtil {
|
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 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;
|
||||||
|
|
||||||
|
public static boolean isSquealing() {
|
||||||
|
return Main.getMainWindow().isRunning();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user