-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartProgram.java
More file actions
119 lines (87 loc) · 3.37 KB
/
StartProgram.java
File metadata and controls
119 lines (87 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package me.AustinNotAustin.AustinsAutoClicker;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
public class StartProgram implements Runnable {
// Set this to true to stop the operation
public static volatile boolean shutdown = true;
// Start the program with the entered information
public static void start() throws AWTException {
System.out.println("startProgram() called");
// Get the interval time
int newInterval = Main.intervalTime();
//System.out.println(newInterval);
//System.out.println(intervalFld.getText());
// If the interval time is greater than 0
if (newInterval > 0) {
//System.out.println("interval is > 0");
// Create the clicking robot
Robot bot = new Robot();
// Set the button to be repeated
int click = InputEvent.BUTTON3_DOWN_MASK;
if (!(Main.isContinuous())) {
try {
Main.repetitions = Integer.parseInt(Main.repetitionFld.getText());
// Clear the notifications
Main.notificationLbl.setText("");
// Reset the active key so there isn't a continuous loop
KeyListener.setActiveKey("");
//System.out.println("The repetitions from repetitionFld.getText() is" + repetitions);
// Disable the objects so the user doesn't make changes while running
Main.disableObjects();
System.out.println("Disable objects was just called in startProgram()");
// Loop through the repetitions until the number is met
for (int i = 0; i < Main.repetitions; i++) {
System.out.println("Clicked: " + (i+1));
bot.mousePress(click);
bot.mouseRelease(click);
Thread.sleep(newInterval);
if (shutdown == true) {
System.out.println("Shutdown was set to true, turning off");
break;
}
}
// Reset the active key so there isn't a continuous loop
KeyListener.setActiveKey("");
// Enable the objects after finishing
Main.enableObjects();
} catch (Exception e) {
// Inform the user that they must enter a number in the repetition field if they want to run the cycle only a number of times
Main.notificationLbl.setText("Please enter a number in the repetition field");
System.out.println(e.getMessage());
}
}
if (Main.isContinuous()) {
// Reset the active key so there isn't a continuous loop
KeyListener.setActiveKey("");
// Limit the maximum times the application will run continuously
int maxReps = 999999;
// Turn off the GUI elements so the user cannot interact during run
Main.disableObjects();
// Continuously loop through the actions
for (int i = 0; i < maxReps; i++) {
System.out.println("Clicked: " + (i+1));
bot.mousePress(click);
bot.mouseRelease(click);
bot.delay(newInterval);
if (shutdown == true) {
System.out.println("Shutdown was set to true, turning off");
break;
}
}
//System.out.println("startProgram -> if isContinuousDone -> for loop -> done with the for loop");
// Enable the objects once the loop finishes
Main.enableObjects();
}
}
}
@Override
public void run() {
try {
start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}