-
Notifications
You must be signed in to change notification settings - Fork 2
/
record-mouse-events.py
108 lines (77 loc) · 2.49 KB
/
record-mouse-events.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
100
101
102
103
104
105
106
107
108
import time
from pynput import mouse
#wtf is this variable name explained?
#m_lc_ = mouse left click
#mch_ = mouse click history
def time_now_mls():
return round(time.time() * 1000)
is_m_lc_down = False
is_m_lc_up = False
#mouse left click pressed vars
m_lc_down_x = 0
m_lc_down_y = 0
#mouse left click released vars
m_lc_up_x = 0
m_lc_up_y = 0
#what mouse button was pressed
mbutton =''
#keep track of time between actions in milliseconds
this_time_ms = time_now_mls()
prev_time_ms = this_time_ms
wait_time_ms = 0
#print("this_time_ms: ",this_time_ms)
#print("prev_time_ms: ",prev_time_ms)
#print("wait_time_ms: ",wait_time_ms)
# store recorded events in dict
mch = {}
def on_move(x, y):
print('Mouse pointer XY: {0}'.format((x, y)))
def on_click(x, y, button, pressed):
global m_lc_down_x
global m_lc_down_y
global m_lc_up_x
global m_lc_up_y
global is_m_lc_down
global is_m_lc_up
global mbutton
global this_time_ms
global prev_time_ms
global wait_time_ms
this_time_ms = time_now_mls()
mbutton = str(button)
wait_time_ms = this_time_ms - prev_time_ms
print('Button Pressed: ', button,' wait_time_ms: ',str(wait_time_ms) )
if pressed:
is_m_lc_down = True
m_lc_down_x = x
m_lc_down_y = y
#print('Event triggered down:', m_lc_down_x, m_lc_down_y)
else:
is_m_lc_up = True
m_lc_up_x = x
m_lc_up_y = y
#print('Event triggered up:', m_lc_up_x, m_lc_up_y)
prev_time_ms = this_time_ms
print('Press Ctrl-C to quit.')
listener = mouse.Listener(on_click=on_click)
listener.start()
try:
event_id = 0
while True:
if is_m_lc_down:
event_id += 1
print('\nIn Loop: m_lc_down:', m_lc_down_x, m_lc_down_y, " event_id: ", event_id)
mch[event_id] = wait_time_ms,mbutton,'m_lc_down_xy', m_lc_down_x, m_lc_down_y
is_m_lc_down = False
if is_m_lc_up:
event_id += 1
print('\nIn Loop: m_lc_up:', m_lc_up_x, m_lc_up_y, " event_id: ", event_id)
mch[event_id] = wait_time_ms,mbutton,'m_lc_up_xy', m_lc_up_x, m_lc_up_y
is_m_lc_up = False
except KeyboardInterrupt:
# end it gracefully
listener.stop()
listener.join()
print("RESULT:")
print(mch)
input('\nDone. Press enter to exit program...')