-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.py
68 lines (36 loc) · 1.35 KB
/
tracker.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
import sys
import math
import time
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QApplication
class Frame:
def __init__(self, position, time):
self.position = position
self.time = time
def speed(self, frame):
d = distance(*self.position, *frame.position)
time_delta = abs(frame.time - self.time)
if time_delta == 0:
return None
else:
return d / time_delta
def distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def get_current_cursor_position():
pos = QCursor.pos()
return pos.x(), pos.y()
def get_current_frame():
return Frame(get_current_cursor_position(), time.time())
if __name__ == '__main__':
app = QApplication(sys.argv)
screen = app.screens()[0]
dpi = screen.physicalDotsPerInch()
last_frame = get_current_frame()
position_prev = get_current_cursor_position()
while True:
new_frame = get_current_frame()
position_now = get_current_cursor_position()
print(f'dpi={ dpi }, distance={ distance(position_prev[0], position_now[0], position_prev[1], position_prev[1])} , cursor: x={ position_now[0] },y={ position_now[1] }, speed={new_frame.speed(last_frame)}')
last_frame = new_frame
time.sleep(0.1)
position_prev = get_current_cursor_position()