Advertisement
Guest User

Untitled

a guest
May 28th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. package brinks;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Dimension;
  5. import java.awt.Rectangle;
  6. import java.awt.Robot;
  7. import java.awt.Toolkit;
  8. import java.awt.event.InputEvent;
  9. import java.awt.image.BufferedImage;
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.nio.file.Path;
  13. import java.util.Random;
  14.  
  15. import javax.imageio.ImageIO;
  16.  
  17. public class Brinks {
  18.  
  19. public static void main(String[] args) {
  20. try {
  21. final Robot r = new Robot();
  22. r.delay(10000); // 10s
  23.  
  24. Runnable prog = new Runnable() {
  25. @Override
  26. public void run() {
  27. new Thread() {
  28. @Override
  29. public void run() {
  30. try {
  31. while (true) {
  32. printScreen(r);
  33. Thread.sleep(15000); // 15s
  34. }
  35. } catch (IOException | InterruptedException e) {
  36. }
  37. };
  38. }.start();
  39. while (true) {
  40. moveMouse(r);
  41. doubleClick(r);
  42. try {
  43. Thread.sleep(5000); // 5s
  44. } catch (InterruptedException e) {
  45. }
  46. }
  47. }
  48. };
  49.  
  50. new Thread(prog).start();
  51. } catch (AWTException e) {
  52. }
  53. }
  54.  
  55. /**
  56. * @param r
  57. * Instance of Robot.
  58. * @throws IOException
  59. * Exception.
  60. *
  61. */
  62. protected static void printScreen(Robot r) throws IOException {
  63. BufferedImage bi = r.createScreenCapture(new Rectangle(0, 0, getScreenSize().width,
  64. getScreenSize().height));
  65.  
  66. File outputfile = new File(getDirSaveFile() + (getPlatform() == 1 ? "\\" : "/")
  67. + getRandomInt(1000000000) + ".jpg");
  68. ImageIO.write(bi, "jpg", outputfile);
  69. }
  70.  
  71. /**
  72. * Mouse left click.
  73. *
  74. * @param r
  75. * Instance of Robot
  76. *
  77. */
  78. protected static void click(Robot r) {
  79. r.mousePress(InputEvent.BUTTON1_MASK);
  80. r.mouseRelease(InputEvent.BUTTON1_MASK);
  81. }
  82.  
  83. /**
  84. * Mouse Double left click
  85. *
  86. * @param r
  87. * Instance of Robot.
  88. *
  89. */
  90. protected static void doubleClick(Robot r) {
  91. click(r);
  92. click(r);
  93. }
  94.  
  95. /**
  96. * @param r
  97. * Instance of Robot.
  98. *
  99. */
  100. protected static void moveMouse(Robot r) {
  101. Dimension d = getScreenSize();
  102. r.mouseMove(d.width - getRandomInt(d.width), d.height - getRandomInt(d.height));
  103. }
  104.  
  105. /**
  106. *
  107. * @param v
  108. * Value to generate random.
  109. * @return Random between 0 and v.
  110. */
  111. private static Integer getRandomInt(int v) {
  112. return new Random().nextInt(v);
  113. }
  114.  
  115. /**
  116. *
  117. * @return Dimension of screen.
  118. */
  119. private static Dimension getScreenSize() {
  120. return Toolkit.getDefaultToolkit().getScreenSize();
  121. }
  122.  
  123. /**
  124. *
  125. * @return Path to paste.
  126. */
  127. protected static Path getDirSaveFile() {
  128. Path p = null;
  129. File f0 = new File("printscreen");
  130. File f = new File(f0.getAbsolutePath());
  131.  
  132. f.mkdirs();
  133. p = f.toPath();
  134.  
  135. return p;
  136. }
  137.  
  138. /**
  139. *
  140. * @return 1 if windows. 0 others platform.
  141. */
  142. public static int getPlatform() {
  143. return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0 ? 1 : 0;
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement