-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTracker.java
58 lines (45 loc) · 1.59 KB
/
Tracker.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
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class Tracker {
private static boolean running = true;
public static void main(String[] args) {
try {
Robot robot = new Robot();
JFrame frame = new JFrame();
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
running = false;
frame.dispose();
}
}
@Override
public void keyReleased(KeyEvent e) {}
});
int centerX = 500;
int centerY = 500;
int radius = 100;
while (running) {
for (int angle = 0; angle < 360; angle++) {
if (!running) break;
double radian = Math.toRadians(angle);
int x = centerX + (int) (radius * Math.cos(radian));
int y = centerY + (int) (radius * Math.sin(radian));
robot.mouseMove(x, y);
robot.delay(10);
}
}
} catch (AWTException e) {
e.printStackTrace();
}
}
}