-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmousePosition.py
99 lines (84 loc) · 2.83 KB
/
mousePosition.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pyautogui as gui
import json
import sys
from pynput.mouse import Listener
import threading
positions = []
gui.FAILSAFE = False
eventos = []
def on_click(x, y, button, pressed):
if pressed == True:
if 'Button.left' in str(button):
print(f'Left Button Pressed ({x},{y})')
eventos.append([x,y])
def ouvindoMouseClick():
print('Evento de clique sendo ouvido...')
with Listener(on_click=on_click) as listener:
try:
listener.run()
except KeyboardInterrupt:
listener.stop()
finally:
listener.stop()
def remover_repetidas(lista):
l = []
for elemento in lista:
if elemento not in l:
l.append(elemento)
return l
def adicionar_evento_de_clique(eventos,positions):
result = []
for position in positions:
for evento in eventos:
if (position[0], position[1]) == (evento[0], evento[1]):
result.append([position[0], position[1], 1])
continue
result.append(position)
return result
try:
if sys.argv[1] == 'gravar':
try:
ouvindoEvento = threading.Thread(target=ouvindoMouseClick)
ouvindoEvento.start()
except KeyboardInterrupt:
exit()
while True:
try:
x,y = gui.position()
positions.append((x,y,0))
except KeyboardInterrupt:
# print('Quantidade total de posições:',len(positions))
# positions = remover_repetidas(positions)
# print('Quantidade de posições válidas:',len(positions))
positions = adicionar_evento_de_clique(eventos,positions)
clicks = 0
for click in positions:
if click[2] == 1:
clicks += 1
if clicks > 0:
clicks = clicks / 2
print('Quantidades de cliques:',int(clicks))
positions = remover_repetidas(positions)
print('Quantidade de posições:',len(positions))
positions = json.dumps(positions)
with open('positions.json', 'wt') as f:
f.write(positions)
f.close()
print('Posições do mouse salvado em -> positions.json')
exit()
except IndexError:
print('\n')
def movimentarMouse():
positions = json.loads(open('positions.json','rt').read())
xy = []
for position in positions:
xy.append(position)
for mouseposition in xy:
print(mouseposition)
gui.moveTo(x=mouseposition[0],y=mouseposition[1],duration=0.1)
def obterPosicao():
positions = json.loads(open('positions.json', 'rt').read())
xyc = []
for position in positions:
xyc.append(position)
return xyc