-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (54 loc) · 1.72 KB
/
main.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
# ref: https://askubuntu.com/questions/1345561/how-can-i-get-absolute-touchpad-coordinates
#1224 804 -> 20 15
import math
import os
import time
#get trackpad absolute coords
from evdev import InputDevice
import argparse
from pynput import mouse
from pynput.mouse import Button
# Initialize parser
parser = argparse.ArgumentParser()
# Adding optional argument
parser.add_argument("-d", "--device", help = "device (event*)")
# Read arguments from command line
args = parser.parse_args()
#SET THIS TO YOUR DEVICE
device = InputDevice('/dev/input/'+ args.device if args.device else 'event7')
touchpad_x_max = 1224
touchpad_y_max = 804
max_x = 1920
max_y = 1080
x = 0
y = 0
def get_xy_coords(e):
#you may need to change this number here; i don't know
if e.code == 53:
global x
x = e.value
#this one too
if e.code == 54:
global y
y = e.value
def mapFromTo(x,a,b,c,d):
# y=(x-a)//(b-a)*(d-c)+c
y=(x-a)/(b-a)*(d-c)+c
return y
x_pos =0
y_pos =0
mouse_controller = mouse.Controller()
for event in device.read_loop():
#rows, cols = stdscr.getmaxyx()
get_xy_coords(event)
if event.code == 54:
prev_x_pos = x_pos
prev_y_pos = y_pos
x_pos =math.floor(mapFromTo(x,0,touchpad_x_max,0,max_x))
y_pos =math.floor(mapFromTo(y,0,touchpad_y_max,0,max_y))
if (abs(prev_x_pos-x_pos)>15 or abs(prev_y_pos-y_pos)>15):
mouse_controller.release(Button.left)
mouse_controller.position = (x_pos,y_pos);
mouse_controller.press(Button.left)
mouse_controller.position = (x_pos,y_pos);
#stdscr.addstr(math.floor(mapFromTo(y,0,touchpad_y_max,0,max_y)),math.floor(mapFromTo(x,0,touchpad_x_max,0,max_x)),char)