Java program to keep computer awake

To keep computer awake we need to press some key or keep mouse pointer moving here and there so that machine does not get locked.In Java we can Robot class to generate many system events.i use the below code to keep my machine running.

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

public class AwakeRobot {

  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Random random = new Random();
   // this code will keep on moving mouse pointer to a random location
    while (true) {
      robot.delay(1000 * 60);
      int x = random.nextInt() % 640;
      int y = random.nextInt() % 480;
      robot.mouseMove(x, y);

    }
  }
}

Posted in Java, Tips tricks | Leave a comment