-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClicker.java
72 lines (61 loc) · 1.67 KB
/
Clicker.java
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
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.InputEvent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Clicker {
private static final int DELAY = 100;
public static void main(String[] args) {
// Make an input reader and read the first line
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = null;
try {
line = in.readLine();
} catch (IOException e) {
// Fail immediately
e.printStackTrace();
return;
}
// Make the Robot to do the clicking
Robot robby = null;
try {
robby = new Robot();
} catch(AWTException e) {
// Fail immediately
e.printStackTrace();
return;
}
// Loop over each line of input
while(line != null) {
// Split it into the three components
String[] pieces = line.split(" ");
int x = Integer.parseInt(pieces[0]);
int y = Integer.parseInt(pieces[1]);
int n = Integer.parseInt(pieces[2]);
// Do the clicking
clickNTimes(x, y, n, robby);
// Get the next line
try {
line = in.readLine();
} catch (IOException e) {
// Fail immediately
e.printStackTrace();
return;
}
}
}
public static void clickNTimes(int x, int y, int n, Robot robby) {
// n times
for(int i = 0; i < n; i++) {
// Move to the desired location (in case someone is moving the mouse)
robby.mouseMove(x, y);
// Press and release
robby.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robby.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
// Probably unneccessary, but I didn't want to cause any issues by
// going as fast as possible
robby.delay(DELAY);
}
}
}