Came across a rare util class of java "Robot" class, which provie the control/auto typing of letter/keyboard controll and screen capering.
sample code
sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Dimension; | |
import java.awt.Rectangle; | |
import java.awt.Robot; | |
import java.awt.Toolkit; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
/** | |
* | |
* @author Rivet Systems | |
*/ | |
public class RobotSample { | |
public static void main(String[] args) throws Exception { | |
for(int i=0;i<2;i++){ | |
captureScreen(System.currentTimeMillis()+"_"+i); | |
} | |
} | |
public static void captureScreen(String fileName) throws Exception { | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |
Rectangle screenRectangle = new Rectangle(screenSize); | |
Robot robot = new Robot(); | |
BufferedImage image = robot.createScreenCapture(screenRectangle); | |
ImageIO.write(image, "png", new File(fileName)); | |
} | |
} |
0 comments:
Post a Comment