mouse mover
This commit is contained in:
commit
6d53341ca6
6
application.yaml
Normal file
6
application.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
# на сколько пикселей сдвигать курсор вправо
|
||||
pixels: 10
|
||||
# через сколько миллисекунд срабатывает триггер (сдвиг вправо)
|
||||
trigger-interval: 1000
|
||||
# через сколько миллисекунд курсор возвращается влево
|
||||
return-interval: 1000
|
||||
31
pom.xml
Normal file
31
pom.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.bvn13</groupId>
|
||||
<artifactId>mouse-mover</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>MouseMover</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
59
src/main/java/MouseMover.java
Normal file
59
src/main/java/MouseMover.java
Normal file
@ -0,0 +1,59 @@
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MouseMover {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Path configPath = Path.of(args.length > 0 ? args[0] : "application.yaml");
|
||||
Map<String, String> config = readYaml(configPath);
|
||||
|
||||
int pixels = intValue(config, "pixels");
|
||||
int triggerInterval = intValue(config, "trigger-interval");
|
||||
int returnInterval = intValue(config, "return-interval");
|
||||
|
||||
System.out.printf("pixels=%d, trigger-interval=%dms, return-interval=%dms%n",
|
||||
pixels, triggerInterval, returnInterval);
|
||||
|
||||
Robot robot = new Robot();
|
||||
while (true) {
|
||||
Thread.sleep(triggerInterval);
|
||||
move(robot, pixels);
|
||||
Thread.sleep(returnInterval);
|
||||
move(robot, -pixels);
|
||||
}
|
||||
}
|
||||
|
||||
private static void move(Robot robot, int dx) {
|
||||
Point p = MouseInfo.getPointerInfo().getLocation();
|
||||
robot.mouseMove(p.x + dx, p.y);
|
||||
}
|
||||
|
||||
private static Map<String, String> readYaml(Path path) throws Exception {
|
||||
Map<String, String> values = new HashMap<>();
|
||||
for (String line : Files.readAllLines(path)) {
|
||||
String trimmed = line.trim();
|
||||
if (trimmed.isEmpty() || trimmed.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
int colon = trimmed.indexOf(':');
|
||||
if (colon < 0) {
|
||||
continue;
|
||||
}
|
||||
values.put(trimmed.substring(0, colon).trim(), trimmed.substring(colon + 1).trim());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private static int intValue(Map<String, String> config, String key) {
|
||||
String value = config.get(key);
|
||||
if (value == null || value.isEmpty()) {
|
||||
throw new IllegalStateException("Missing property: " + key);
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user