Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Commit 6be2468

Browse files
committed
Initial commit
0 parents  commit 6be2468

22 files changed

Lines changed: 1448 additions & 0 deletions

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.metadata/**
2+
.recommenders/**
3+
*.class
4+
*.dtd
5+
*.lst
6+
*.lock
7+
*.lo
8+
*.jar
9+
*.project
10+
*.classpath
11+
*.prefs
12+
*.map
13+
*.zip
14+
*.sha
15+
*.sha
16+
**/build.xml
17+
**/pom.xml
18+
*.MF
19+
*.sh
20+
keybinds.txt
21+
settings_bool.txt
22+
settings_num.txt

Lang.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Home tab text
2+
0:Home
3+
1:Home
4+
2:Version History
5+
3:Usage Guide
6+
4:This is the guide data
7+
31:Welcome to Clicker
8+
32:Hello! I don't know what to put here right now. So for now I'll just have this placeholder text.\n\nClick the items on the menu to see their information.
9+
// Controls tab text
10+
100:Controls
11+
101:Key ID=
12+
111:Toggle Stat Recording
13+
112:Toggle Clicker
14+
113:Toggle GUI
15+
// Settings tab text
16+
200:Settings
17+
201:Active
18+
211:Minimum Delay
19+
212:Maximum Delay
20+
213:Average Delay
21+
214:Deviation
22+
215:Targeted Window
23+
216:Choose a Window
24+
// Statistics tab text
25+
300:Statistics
26+
301:Record some data for details to appear here.
27+
// Changelog
28+
401:Initial release

src/me/coley/clicker/Clicker.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package me.coley.clicker;
2+
3+
import java.util.Random;
4+
import java.util.logging.Level;
5+
6+
import me.coley.clicker.ui.BotGUI;
7+
import me.coley.jnathread.Mouse;
8+
import me.coley.jnathread.Windows;
9+
10+
/**
11+
* Handler for the clicking process.
12+
*
13+
* @author Matt
14+
*
15+
*/
16+
public class Clicker {
17+
private boolean status;
18+
private static String target;
19+
20+
public void toggle() {
21+
status = !status;
22+
if (status) {
23+
onEnable();
24+
} else {
25+
BotGUI.log.log(Level.INFO, "Stopping clicker thread...");
26+
}
27+
}
28+
29+
private void onEnable() {
30+
BotGUI.log.log(Level.INFO, "Launching clicker thread...");
31+
new Thread() {
32+
private final Random r = new Random();
33+
34+
@Override
35+
public void run() {
36+
while (status) {
37+
if (canClick()) {
38+
Mouse.mouseLeftClick(-1, -1);
39+
}
40+
try {
41+
double dev = BotGUI.settings.getNumericSetting(Values.SET_DEV_DELAY).getCurrent();
42+
double mean = BotGUI.settings.getNumericSetting(Values.SET_AVG_DELAY).getCurrent();
43+
int min = BotGUI.settings.getNumericSetting(Values.SET_MIN_DELAY).getCurrent();
44+
int max = BotGUI.settings.getNumericSetting(Values.SET_MAX_DELAY).getCurrent();
45+
// Gaussian random sleep. Tends to sleep with times
46+
// around the mean. Times near the bounds (min/max) are
47+
// less common.
48+
long sleep = (long) clamp(Math.round(r.nextGaussian() * dev + mean), min, max);
49+
Thread.sleep(sleep);
50+
} catch (InterruptedException e) {
51+
e.printStackTrace();
52+
}
53+
}
54+
}
55+
56+
private long clamp(double val, int min, int max) {
57+
// Java needs to implement a clamp function in java.util.math...
58+
return (long) Math.max(min, Math.min(max, val));
59+
}
60+
}.start();
61+
}
62+
63+
/**
64+
* Checks if a target window needs to be active.
65+
*
66+
* @return
67+
*/
68+
private static boolean canClick() {
69+
if (BotGUI.settings.getBooleanSetting(Values.SET_WINDOW_TARGET).getCurrent() && target != null) {
70+
if (Windows.getCurrentWindowTitle().equals(target)) {
71+
return true;
72+
} else {
73+
return false;
74+
}
75+
}
76+
return true;
77+
}
78+
79+
/**
80+
* Sets the clicker's target window.
81+
*
82+
* @param target
83+
*/
84+
public void setTargetWindow(String target) {
85+
Clicker.target = target;
86+
}
87+
}

src/me/coley/clicker/Keybinds.java

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package me.coley.clicker;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import org.apache.commons.io.FileUtils;
10+
11+
import com.google.common.collect.Maps;
12+
13+
import me.coley.clicker.util.Saveable;
14+
import me.coley.clicker.value.Updatable;
15+
16+
public class Keybinds implements Saveable {
17+
private static final File fileBinds = new File("keybinds.txt");
18+
19+
private static final Map<Integer, String> conv = Maps.newHashMap();
20+
private Map<Integer, Updatable> registered = Maps.newHashMap();
21+
private Map<Integer, Integer> keybinds = Maps.newHashMap();
22+
private Map<Integer, String> names = Maps.newHashMap();
23+
24+
public static int BIND_TOGGLE_RECORDING = 100;
25+
public static int BIND_TOGGLE_CLICKER = 101;
26+
public static int BIND_TOGGLE_GUI = 102;
27+
28+
public void setKeyValue(int settingID, String name, int value) {
29+
keybinds.put(settingID, value);
30+
names.put(settingID, name);
31+
}
32+
33+
public void update(int settingID, int value) {
34+
if (keybinds.containsKey(settingID)) {
35+
keybinds.put(settingID, value);
36+
if (registered.containsKey(settingID)) {
37+
registered.get(settingID).update();
38+
}
39+
}
40+
}
41+
42+
public void register(int settingID, Updatable updateable) {
43+
registered.put(settingID, updateable);
44+
}
45+
46+
public Map<Integer, Integer> getKeybinds() {
47+
return keybinds;
48+
}
49+
50+
public int getKey(int key) {
51+
return keybinds.get(key);
52+
}
53+
54+
public String getName(int settingID) {
55+
return names.get(settingID);
56+
}
57+
58+
public static String getKeyName(int vkCode) {
59+
if (!conv.containsKey(vkCode)) { return " ??? "; }
60+
return conv.get(vkCode);
61+
}
62+
63+
@Override
64+
public void load() {
65+
try {
66+
if (fileBinds.exists()) {
67+
List<String> linesN = FileUtils.readLines(fileBinds);
68+
for (String line : linesN) {
69+
if (line.startsWith("/")) continue;
70+
String[] data = line.split(":");
71+
// NAME : ID : VALUE
72+
int key = Integer.parseInt(data[1]);
73+
int value = Integer.parseInt(data[2]);
74+
update(key, value);
75+
}
76+
}
77+
} catch (IOException e) {
78+
e.printStackTrace();
79+
}
80+
}
81+
82+
@Override
83+
public void save() {
84+
try {
85+
if (!fileBinds.exists()) {
86+
fileBinds.createNewFile();
87+
}
88+
List<String> linesN = new ArrayList<String>(keybinds.size());
89+
for (int i : keybinds.keySet()) {
90+
// NAME : ID : VALUE
91+
linesN.add(names.get(i) + ":" + i + ":" + keybinds.get(i).intValue());
92+
}
93+
FileUtils.writeLines(fileBinds, linesN);
94+
} catch (IOException e) {
95+
e.printStackTrace();
96+
}
97+
}
98+
99+
static {
100+
conv.put(65, "A");
101+
conv.put(66, "B");
102+
conv.put(67, "C");
103+
conv.put(68, "D");
104+
conv.put(69, "E");
105+
conv.put(70, "F");
106+
conv.put(71, "G");
107+
conv.put(72, "H");
108+
conv.put(73, "I");
109+
conv.put(74, "J");
110+
conv.put(75, "K");
111+
conv.put(76, "L");
112+
conv.put(77, "M");
113+
conv.put(78, "N");
114+
conv.put(79, "O");
115+
conv.put(80, "P");
116+
conv.put(81, "Q");
117+
conv.put(82, "R");
118+
conv.put(83, "S");
119+
conv.put(84, "T");
120+
conv.put(85, "U");
121+
conv.put(86, "V");
122+
conv.put(87, "W");
123+
conv.put(88, "X");
124+
conv.put(89, "Y");
125+
conv.put(90, "Z");
126+
conv.put(49, "1");
127+
conv.put(50, "2");
128+
conv.put(51, "3");
129+
conv.put(52, "4");
130+
conv.put(53, "5");
131+
conv.put(54, "6");
132+
conv.put(55, "7");
133+
conv.put(56, "8");
134+
conv.put(57, "9");
135+
conv.put(48, "0");
136+
conv.put(189, "-");
137+
conv.put(187, "=");
138+
conv.put(219, "[");
139+
conv.put(221, "]");
140+
conv.put(186, ";");
141+
conv.put(222, "'");
142+
conv.put(191, "/");
143+
conv.put(220, "\\");
144+
conv.put(190, ".");
145+
conv.put(32, "SPACE");
146+
conv.put(162, "L-CTRL");
147+
conv.put(163, "R-CTRL");
148+
conv.put(160, "L-SHIFT");
149+
conv.put(161, "R-SHIFT");
150+
conv.put(46, "DELETE");
151+
conv.put(36, "HOME");
152+
conv.put(164, "L-ALT");
153+
conv.put(165, "R-ALT");
154+
conv.put(9, "TAB");
155+
conv.put(188, ",");
156+
conv.put(192, "`");
157+
}
158+
}

src/me/coley/clicker/Stats.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package me.coley.clicker;
2+
3+
import java.util.logging.Level;
4+
5+
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
6+
7+
import me.coley.clicker.ui.BotGUI;
8+
import me.coley.jnathread.hook.mouse.MouseEventReceiver;
9+
import me.coley.jnathread.hook.mouse.MouseHook;
10+
import me.coley.jnathread.hook.mouse.struct.MOUSEHOOKSTRUCT;
11+
import me.coley.jnathread.hook.mouse.struct.MouseButtonType;
12+
13+
/**
14+
* Handler for the recording mouse inputs.
15+
*
16+
* @author Matt
17+
*
18+
*/
19+
public class Stats {
20+
private boolean status;
21+
private DescriptiveStatistics clickFrequency;
22+
private DescriptiveStatistics clicksX;
23+
private DescriptiveStatistics clicksY;
24+
private MouseEventReceiver lastMouseHook;
25+
26+
private void onDisable() {
27+
// Finished, save stats
28+
BotGUI.log.log(Level.INFO, "Finished recording.");
29+
if (lastMouseHook != null) {
30+
MouseHook.unhook(lastMouseHook);
31+
}
32+
BotGUI.onRecordingFinished();
33+
}
34+
35+
private void onEnable() {
36+
// Start new stats
37+
BotGUI.log.log(Level.INFO, "Beginning recording of mouse input.");
38+
clickFrequency = new DescriptiveStatistics();
39+
clicksX = new DescriptiveStatistics();
40+
clicksY = new DescriptiveStatistics();
41+
BotGUI.log.log(Level.INFO, "Creating keybind-listener...");
42+
MouseEventReceiver me = new MouseEventReceiver() {
43+
private long last = -1;
44+
45+
@Override
46+
public boolean onMousePress(MouseButtonType type, MOUSEHOOKSTRUCT info) {
47+
long now = System.currentTimeMillis();
48+
if (last != -1) {
49+
clickFrequency.addValue(now - last);
50+
}
51+
last = now;
52+
clicksX.addValue(info.pt.x);
53+
clicksY.addValue(info.pt.y);
54+
return false;
55+
}
56+
57+
@Override
58+
public boolean onMouseRelease(MouseButtonType type, MOUSEHOOKSTRUCT info) {
59+
return false;
60+
}
61+
62+
@Override
63+
public boolean onMouseScroll(boolean down, MOUSEHOOKSTRUCT info) {
64+
return false;
65+
}
66+
67+
@Override
68+
public boolean onMouseMove(MOUSEHOOKSTRUCT info) {
69+
return false;
70+
}
71+
};
72+
MouseHook.hook(me);
73+
}
74+
75+
public void toggle() {
76+
status = !status;
77+
if (status) {
78+
onEnable();
79+
} else {
80+
onDisable();
81+
}
82+
}
83+
84+
public DescriptiveStatistics getFrequencyData() {
85+
return clickFrequency;
86+
}
87+
88+
public DescriptiveStatistics getPosXData() {
89+
return clicksX;
90+
}
91+
92+
public DescriptiveStatistics getPosYData() {
93+
return clicksY;
94+
}
95+
96+
}

0 commit comments

Comments
 (0)