-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclick.py
82 lines (55 loc) · 1.59 KB
/
click.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
73
74
75
76
import sys
import pyautogui
from pynput.keyboard import Key, Listener
import threading
thread_list =[]
def clicker(numberOfIterations, coords):
for _ in range(numberOfIterations):
for i in coords:
x = i[0]
y = i[1]
n = i[2]
for __ in range(int(n)):
pyautogui.moveTo(int(x), int(y), duration=0.1)
pyautogui.mouseDown()
pyautogui.mouseUp()
print("clicked (" + str(x) + "," + str(y) +")")
def listen():
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
def on_press(key):
#print('{0} pressed'.format(key))
pass
def on_release(key):
#print('{0} release'.format(key))
if str(key) == "'p'":
thread = threading.Thread(target=clicker,args=( numberOfIterations ,coords, ) )
thread_list.append(thread)
thread.start()
if key == Key.esc:
# Stop listener
return False
numberOfIterations = 1
coords = []
if len(sys.argv) > 1:
if( sys.argv[1].isdigit() ):
numberOfIterations = sys.argv[1]
else:
print("Error!\nnumber of iterations must be a valid number!")
exit(0)
try:
f = open("Coordinates.txt","r")
try:
for i in f.readlines():
coords.append(i.split())
except:
print("Error!\nCoordinates.txt file is empty!")
exit(0)
except:
print("Error!\nCoordinates.txt file not found!")
exit(0)
thread1 = threading.Thread(target=listen)
thread_list.append(thread1)
thread1.start()