import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* This program will keep your computer alive i.e. it does not let computer go in Idle mode.
* Default wake up time = 1 min
*/
public class KeepAliveRobot{
private static boolean pause = true;
private static final int DEFAULT_SLEEP_TIME = 60000; // 60000 miliseconds = 1 min
public static void main(String[] args)
throws AWTException,IOException {
Robot robot = new Robot();
Properties p = new Properties();
int sleepTime = DEFAULT_SLEEP_TIME;
try {
p.load(new FileInputStream("live.properties"));
sleepTime = Integer.parseInt(p.getProperty("wakeup.time"));
} catch (Exception e) {
e.printStackTrace();
}
while (pause) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e1) {
break;
}
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_ALT);
}
}
}
This is a place where you can find some hard searched, some regularly used, some fundoo - innovative, and some my own RnD utility stuff.
Visitor's questions, suggestions, comments are welcome.
Wednesday, June 01, 2011
Java Robot Example - Program to keep your computer away from Idle mode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment