Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package brinks;
- import java.awt.AWTException;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.event.InputEvent;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Path;
- import java.util.Random;
- import javax.imageio.ImageIO;
- public class Brinks {
- public static void main(String[] args) {
- try {
- final Robot r = new Robot();
- r.delay(10000); // 10s
- Runnable prog = new Runnable() {
- @Override
- public void run() {
- new Thread() {
- @Override
- public void run() {
- try {
- while (true) {
- printScreen(r);
- Thread.sleep(15000); // 15s
- }
- } catch (IOException | InterruptedException e) {
- }
- };
- }.start();
- while (true) {
- moveMouse(r);
- doubleClick(r);
- try {
- Thread.sleep(5000); // 5s
- } catch (InterruptedException e) {
- }
- }
- }
- };
- new Thread(prog).start();
- } catch (AWTException e) {
- }
- }
- /**
- * @param r
- * Instance of Robot.
- * @throws IOException
- * Exception.
- *
- */
- protected static void printScreen(Robot r) throws IOException {
- BufferedImage bi = r.createScreenCapture(new Rectangle(0, 0, getScreenSize().width,
- getScreenSize().height));
- File outputfile = new File(getDirSaveFile() + (getPlatform() == 1 ? "\\" : "/")
- + getRandomInt(1000000000) + ".jpg");
- ImageIO.write(bi, "jpg", outputfile);
- }
- /**
- * Mouse left click.
- *
- * @param r
- * Instance of Robot
- *
- */
- protected static void click(Robot r) {
- r.mousePress(InputEvent.BUTTON1_MASK);
- r.mouseRelease(InputEvent.BUTTON1_MASK);
- }
- /**
- * Mouse Double left click
- *
- * @param r
- * Instance of Robot.
- *
- */
- protected static void doubleClick(Robot r) {
- click(r);
- click(r);
- }
- /**
- * @param r
- * Instance of Robot.
- *
- */
- protected static void moveMouse(Robot r) {
- Dimension d = getScreenSize();
- r.mouseMove(d.width - getRandomInt(d.width), d.height - getRandomInt(d.height));
- }
- /**
- *
- * @param v
- * Value to generate random.
- * @return Random between 0 and v.
- */
- private static Integer getRandomInt(int v) {
- return new Random().nextInt(v);
- }
- /**
- *
- * @return Dimension of screen.
- */
- private static Dimension getScreenSize() {
- return Toolkit.getDefaultToolkit().getScreenSize();
- }
- /**
- *
- * @return Path to paste.
- */
- protected static Path getDirSaveFile() {
- Path p = null;
- File f0 = new File("printscreen");
- File f = new File(f0.getAbsolutePath());
- f.mkdirs();
- p = f.toPath();
- return p;
- }
- /**
- *
- * @return 1 if windows. 0 others platform.
- */
- public static int getPlatform() {
- return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? 1 : 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement