Java - simple auto mouse mover application
How to write simple automatic mouse movement app in java?
Is it possible to write very simple app to do only that, without any additional logic.
I am only interested in couple of mouse moves from point 1 to point 2 on my computer screen. On the web I can find kind of complicated apps that do a lot of different stuff.
Quick solution:
xxxxxxxxxx
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
public class SimpleAutoMouseMover extends JPanel {
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame();
frame.setSize(450, 350);
frame.setLocation(300, 300);
frame.setVisible(true);
Robot robot = new Robot();
for (int i = 0; i < 3; i++) {
System.out.println("move to 300px, 300px");
robot.mouseMove(300, 300);
System.out.println("sleep 3 sec");
Thread.sleep(3000);
System.out.println("move to 200px, 200px");
robot.mouseMove(200, 200);
System.out.println("sleep 3 sec");
Thread.sleep(3000);
}
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
frame.dispose();
System.exit(0);
}
}
Output:
xxxxxxxxxx
move to 300px, 300px
sleep 3 sec
move to 200px, 200px
sleep 3 sec
move to 300px, 300px
sleep 3 sec
move to 200px, 200px
sleep 3 sec
move to 300px, 300px
sleep 3 sec
move to 200px, 200px
sleep 3 sec
This simple app will do exactly what you ask in question, move the mouse from one point to another. In this case from point(300px, 300px) to point(200px, 200px) and back again - it will be repeated 3 times.
Flow:
- from point(300px, 300px) to point(200px, 200px)
- sleep 3 seconds
- from point(200px, 200px) to point(300px, 300px)
- sleep 3 seconds
- repeat again
We can use while (true) instead of for loop, but before using while true - think twice and add some break condition.
This simple app can be easily modified and we can add some more features like auto click. Java has nice API to do those things.