Search Results


Tuesday, August 23, 2016

Automatic java mouse mover

There are many solutions to moving mouse automatically to keep the screen active in windows.

For java programmers, simple solution is to write a java program to move the mouse automatically.


package movemouse;

import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.Robot;

import java.util.Random;

public class moveMouse {
    public moveMouse() {
        super();
    }

    public static final int WAIT = 60 * 1000; // SECONDS
    public static final int OFFSET = 3;

    public static void main(String... args) throws Exception {
        int x, y;
        Robot robot = new Robot();
        Random random = new Random();
        PointerInfo a;

        while (true) {

            a = MouseInfo.getPointerInfo();
            x = (int) a.getLocation().getX();
            y = (int) a.getLocation().getY();
            robot.mouseMove(+ OFFSET, y + OFFSET);
            Thread.sleep(WAIT);

            a = MouseInfo.getPointerInfo();
            x = (int) a.getLocation().getX();
            y = (int) a.getLocation().getY();
            robot.mouseMove(- OFFSET, y - OFFSET);
            Thread.sleep(WAIT);
        }
    }
}



Compile and Enjoy!

If you don't have jdk use this jar file (moused.jarred). Open the link and clikc on Download button to download the file and then rename it to jar. Use the following command to execute it.

java -jar moused.jar

No comments :