This was a hack to grab the questions from a paid online quiz. Idea here is, this program will run as a deamon in the background and take the screen shot every 10 second and save it into a jpeg file on temp directory.
public void captureFullScreen() {
try {
Robot robot = new Robot();
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
File target = new File(saveLocation, imageName + "_" + System.currentTimeMillis() + "." + imageType);
saveImageToFile(robot.createScreenCapture(area), target);
} catch (AWTException e) {
System.err.println("Exception while capturing screen. " + e);
}
}
/**
* Saves the specified RenderedImage to the specified File.
*
* @param renderedImage the image to write to file.
* @param target the file to write the image to.
*/
private void saveImageToFile(RenderedImage renderedImage, File target) {
try {
ImageIO.write(renderedImage, imageType, target);
} catch (IOException e) {
System.err.println(e);
}
}
and now the Deamon
public static void main(String args[]) throws InterruptedException {
while(true)
{
new ScreenGraber().captureFullScreen();
Thread.sleep(10000); // will sleep for 10 seconds
}
}
0 Comments:
Post a Comment