-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackprocessor.py
More file actions
53 lines (47 loc) · 2.05 KB
/
trackprocessor.py
File metadata and controls
53 lines (47 loc) · 2.05 KB
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
import pyautogui
sensitivity_factor = 4.5 # recommended to be in the range [3,5] for comfort
leap_bound = 20 # assertion that the cursor can't be moved more than 25 pixels
pyautogui.PAUSE = 0.01 # remove delay! can't be zero from hardware limitations
pyautogui.FAILSAFE = False # allow for the corners to be reached by the cursor
def oneTouchTracker(message, received_coords):
"""
Process one finger mouse tracking network requests.
"""
if message == "C":
pyautogui.click()
received_coords[0][1] = False # flag reset to prepare for next call
elif message == "RC":
pyautogui.click(button='right')
received_coords[0][1] = False
elif message == "SU":
pyautogui.scroll(30)
received_coords[0][1] = False
elif message == "SD":
pyautogui.scroll(-30)
received_coords[0][1] = False
elif message == "SL": # left scrolling is supported only in Linux and Mac OSX
pyautogui.hscroll(-30)
received_coords[0][1] = False
elif message == "SR": # right scrolling is supported only in Linux and Mac OSX
pyautogui.hscroll(30)
received_coords[0][1] = False
else:
coords = message.split(",")
new_x = int(coords[0].strip())
new_y = int(coords[1].strip())
if not received_coords[0][1]:
received_coords[0][0][0] = new_x
received_coords[0][0][1] = new_y
received_coords[0][1] = True
elif not received_coords[1]:
curr_x, curr_y = pyautogui.position()
trans_x = (new_x - received_coords[0][0][0])
trans_y = (new_y - received_coords[0][0][1])
if abs(trans_x) > leap_bound or abs(trans_y) > leap_bound:
received_coords[0][1] = False
return received_coords
trans_x *= sensitivity_factor
trans_y *= sensitivity_factor
pyautogui.moveTo(curr_x + trans_x , curr_y + trans_y)
received_coords[0][1] = False
return received_coords