Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. package com.ruffian7.sevenclicker;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Point;
  5. import java.awt.Robot;
  6. import java.util.Random;
  7. import java.util.logging.Level;
  8. import java.util.logging.LogManager;
  9. import java.util.logging.Logger;
  10.  
  11. import javax.swing.ImageIcon;
  12.  
  13. import org.jnativehook.GlobalScreen;
  14. import org.jnativehook.NativeHookException;
  15.  
  16. import com.ruffian7.sevenclicker.gui.ClickerGui;
  17. import com.ruffian7.sevenclicker.listener.KeyListener;
  18. import com.ruffian7.sevenclicker.listener.MouseListener;
  19.  
  20. public class AutoClicker {
  21.  
  22. public static Robot robot;
  23. public static Point mousePos;
  24. public static ClickerGui gui = new ClickerGui();
  25.  
  26. public static boolean toggled = false;
  27. public static boolean activated = false;
  28. public static boolean skipNext = false;
  29. public static boolean blockHit = false;
  30.  
  31. private static int delay = -1;
  32. public static long lastTime = 0;
  33. public static int minCPS = 8;
  34. public static int maxCPS = 12;
  35. public static int button = 1;
  36.  
  37. public static String[] toggleKey = { "", "" };
  38. public static int toggleMouseButton = 3;
  39.  
  40. public static void main(String[] args) {
  41. LogManager.getLogManager().reset();
  42. Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF);
  43.  
  44. try {
  45. robot = new Robot();
  46. GlobalScreen.registerNativeHook();
  47. GlobalScreen.addNativeMouseListener(new MouseListener());
  48. GlobalScreen.addNativeKeyListener(new KeyListener());
  49. } catch (NativeHookException | AWTException e) {
  50. e.printStackTrace();
  51. }
  52.  
  53. try {
  54. while (true) {
  55. Thread.sleep(1);
  56. Random random = new Random();
  57. if (delay == -1)
  58. delay = random.nextInt((1000 / minCPS) - (1000 / maxCPS) + 1) + (1000 / maxCPS);
  59.  
  60. if (activated && toggled && !gui.focused) {
  61. if (System.currentTimeMillis() - lastTime >= delay) {
  62. click();
  63. lastTime = System.currentTimeMillis();
  64. delay = random.nextInt((1000 / minCPS) - (1000 / maxCPS) + 1) + (1000 / maxCPS);
  65. }
  66. }
  67. }
  68. } catch (InterruptedException e) {
  69. e.printStackTrace();
  70. }
  71. }
  72.  
  73. private static void click() {
  74. skipNext = true;
  75. robot.mousePress((button == 1) ? 16 : 4);
  76. robot.mouseRelease((button == 1) ? 16 : 4);
  77.  
  78. if (blockHit) {
  79. robot.mousePress((button == 1) ? 4 : 16);
  80. robot.mouseRelease((button == 1) ? 4 : 16);
  81. }
  82. }
  83.  
  84. public static void toggle() {
  85. if (AutoClicker.toggled) {
  86. AutoClicker.toggled = false;
  87. AutoClicker.gui.powerButton
  88. .setIcon(new ImageIcon(AutoClicker.class.getClassLoader().getResource("assets/power_button.png")));
  89. } else {
  90. AutoClicker.toggled = true;
  91. AutoClicker.gui.powerButton.setIcon(
  92. new ImageIcon(AutoClicker.class.getClassLoader().getResource("assets/power_button_on.png")));
  93. }
  94.  
  95. AutoClicker.activated = false;
  96. AutoClicker.skipNext = false;
  97. AutoClicker.blockHit = false;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement