-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
72 lines (62 loc) · 2.36 KB
/
bot.py
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 sys
import time
import pyautogui
from base import Base
pyautogui.PAUSE = 0.1
class Miner(Base):
def init(self):
self.db = self.brain.brain
self._make_db()
self.setTimeout(1, print, "Press ESC to exit")
def _make_db(self):
if not self.db.get("Miner", return_false=True): # return False if not found
self.db.set("Miner", {"clicks": []})
self.brain.save()
def onPress(self):
def exit():
print("ESC Key Pressed: exiting..")
self.loop = False
sys.exit()
if len(self.pressed) == 1:
key = self.pressed[0]
if "_name_" in key.__dict__:
if key._name_ == "esc":
self.setTimeout(1, exit)
if len(self.pressed) > 1:
combo = self.pressed[1].char
if combo == '\x10': # ctrl + P
self.speech.talk("Logging clicks")
self.log_clicks = True
elif combo == '\x08': # ctrl + H
self.speech.talk("Stopped logging clicks")
self.log_clicks = False
elif combo == '\x16': # ctrl + V
self.speech.talk("Running clicks")
self.run_clicks = True
elif combo == '\x19': # ctrl + Y
self.speech.talk("Stopped running clicks")
self.run_clicks = False
def onClick(self, x, y, button, pressed):
if pressed and self.log_clicks:
self.db.Miner.clicks.append({
"x": x,
"y": y,
"button": str(button),
"time": time.time()
})
self.brain.save()
def onLoop(self):
if self.run_clicks:
clicks = self.db.Miner.clicks
for index, click in enumerate(clicks):
secs = click['time']
if len(clicks) + 1 > index + 1:
index = 0
secs = int(clicks[index + 1]['time'] - click['time'])
pyautogui.moveTo(click['x'], click['y'], duration=0.5)
pyautogui.click(click['x'], click['y'], button=click['button'].split(".")[1])
if secs > 0:
time.sleep(secs)
if __name__=="__main__":
bot = Miner()
bot.main()