I Need help to make this Java Bot work only when the PC is idle

Hello Fellow Coders,

I have this Java Bot that my brother and I programmed. It makes the mouse move automatically every 3 seconds. Nonetheless, I need it to do exactly that, but when the PC is idle only. Perhaps after 3 seconds of idle time.

Anyone knows how to do it?

Read below to see the code:

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

public class Index {
public static final int FIVE_SECONDS = 3000;
public static final int MAX_Y = 300;
public static final int MAX_X = 300;
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));

        Thread.sleep(FIVE_SECONDS);
    }
}

}