Auto mouse mover Java code

April 01, 2021

Auto Mouse Mover program allows mouse to move automatically without human interaction and keeps the computer without log off. This code will be usefull when we run any automation code in our desktop and system never goes to sleep mode.

Save the below java program in a file and run it whenever necessary. No third party installation software needed.

package com.bhuvaneswaran;

import java.awt.Robot;
import java.util.Random;

public class MouseMovement {
    public static final int FIVE_SECONDS = 5000;
    public static final int MAX_Y = 400;
    public static final int MAX_X = 400;

    public static void main(String... args) throws Exception {
        Robot robot = new Robot();
        Random random = new Random();
        while (true) {
            robot.mouseMove(random.nextInt(MAX_X), random.nextInt(MAX_Y));

Profile picture

I'm a software engineer, lives in Chennai, India. Full Stack developer and Certified Microsoft Azure DevOps Expert. Love to travel, cycling, reading non-fiction books, architecture photography. Fan of Minimalism.
More about me → My Projects →