-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
108 lines (90 loc) · 3.16 KB
/
Main.java
File metadata and controls
108 lines (90 loc) · 3.16 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
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class Main {
static class Bot {
Robot robot;
public Bot() throws AWTException {
this.robot = new Robot();
}
public Bot(Robot robot) {
this.robot = robot;
}
public void leftClick() {
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
public void rightClick() {
robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
}
public void leftHold() {
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
}
public void leftUnhold() {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
public void rightHold() {
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
}
public void rightUnhold() {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
// moves mouse to coords (pixels counted from top left)
public void moveMouse(double xCord, double yCord) {
// fixing coordinates according to 1920x1080 screen pixels
xCord /= 1.25;
yCord /= 1.25;
int x = (int) Math.round(xCord);
int y = (int) Math.round(yCord);
robot.mouseMove(x, y);
}
// paste a string
public void paste(String text) {
StringSelection stringSelection = new StringSelection(text);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
}
// type a string character by character
public void type(String keys, int delay) {
for (char c : keys.toCharArray()) {
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
if (KeyEvent.CHAR_UNDEFINED == keyCode) {
throw new RuntimeException("Key code not found for character '" + c + "'");
}
robot.keyPress(keyCode);
robot.keyRelease(keyCode);
robot.delay(delay);
}
}
public void keyClick(int key) {
robot.keyPress(key);
robot.keyRelease(key);
}
// hax
public void autoClicker(int cps, int clicks) {
while (clicks-- > 0) {
leftClick();
robot.delay(Math.round(1000 / cps));
}
}
}
public static void main(String[] args) {
Bot bot;
try {
bot = new Bot();
bot.leftClick();
bot.paste("Hello World!");
} catch (AWTException e) {
e.printStackTrace();
}
}
}