-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtouchpad.py
77 lines (65 loc) · 1.93 KB
/
touchpad.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
#!/usr/bin/env python3
import struct
import time
import math
import glob
import uinput
import pyudev
import os
from ft5406 import Touchscreen, TS_PRESS, TS_RELEASE, TS_MOVE
from math import floor
def read_and_emulate_mouse(event, touch):
global startX
global startY
global startTime
global mouse
if event == TS_PRESS:
# print("Got Press", touch)
(startX, startY) = touch.position
startTime = time.time()
# if event == TS_RELEASE:
# print("Got release", touch)
# if event == TS_MOVE:
# print("Got move", touch)
(x, y) = touch.position
(last_x, last_y) = touch.last_position
movement = math.sqrt(pow(x - startX, 2) + pow(y - startY, 2))
if movement < 20:
if event == TS_RELEASE:
duration = time.time() - startTime
if duration > 1:
print("Right click")
mouse.emit(uinput.BTN_RIGHT, 1)
mouse.emit(uinput.BTN_RIGHT, 0)
(startX, startY) = touch.position
else:
print("Left click")
mouse.emit(uinput.BTN_LEFT, 1)
mouse.emit(uinput.BTN_LEFT, 0)
(startX, startY) = touch.position
else:
mouse.emit(uinput.REL_X, x - last_x, syn=False)
mouse.emit(uinput.REL_Y, y - last_y)
if __name__ == "__main__":
global mouse
os.system("modprobe uinput")
#os.system("chmod 666 /dev/hidraw*")
os.system("chmod 666 /dev/uinput*")
mouse = uinput.Device([
uinput.BTN_LEFT,
uinput.BTN_RIGHT,
uinput.REL_X,
uinput.REL_Y,
])
ts = Touchscreen()
for touch in ts.touches:
touch.on_press = read_and_emulate_mouse
touch.on_release = read_and_emulate_mouse
touch.on_move = read_and_emulate_mouse
ts.run()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
ts.stop()
exit()