In real time situation, sometimes we need our system should be active or it should not go to sleep mode while executing some programs. And we do not have admin rights for our system to change the sleep time for our system.
As a workaround we can move our mouse pointer after a certain time so that the system should not get into sleep mode or always in Active mode till the mouse pointer programs is executing.
Let us look into the program for moving the mouse pointer using Java -
import java.awt.Robot;
import java.util.Random;
public class MouseMover {
public static final int TIME_IN_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));
Thread.sleep(TIME_IN_SECONDS);
}
}
}
In the above program we are moving the mouse pointer after every 5 seconds.We set the maximum X and Y axis of the screen in which the mouse pointer will be moving to make the System active.
No comments:
Post a Comment