diff --git a/README.md b/README.md new file mode 100644 index 0000000..ade1c4c --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Touchpaddraw + +This is a simple python script that converts touchpad to graphics tablet... + +> :warning: Still this is in /prototype/ phase and still require *root* privilages... use this *AT YOUR OWN RISK*... i am not getting time to work on this (need to rewrite this in rust or c)... +> :warning: NO support for wayland(yet) + +## Demo + +[![demo yt video for touchpad draw](https://img.youtube.com/vi/jfI_lGY1dHM/0.jpg)](https://www.youtube.com/watch?v=jfI_lGY1dHM) + +## how to use + +clone this repo +``` +git clone https://github.com/Vaisakhkm2625/touchpaddraw.git +``` +or +``` +git clone git@github.com:Vaisakhkm2625/touchpaddraw.git +``` + +install `evtest` + +Run `sudo evtest` and find the event of your touchpad + +``` +/dev/input/event8: MSFT0001:01 06CB:CE2D Touchpad +``` +means you have `event8` + +install python packages +``` +sudo pip install evdev +sudo pip install pynput +``` +(if you are not able to install, see: https://github.com/gvalkov/python-evdev/issues/164) + + +TODO: (libevdev or evdev) + +then run + +```bash +sudo python main.py -d event8 + +``` +accouding to your event number + + + diff --git a/main.py b/main.py index 6ebe9e8..4f8165e 100644 --- a/main.py +++ b/main.py @@ -5,10 +5,13 @@ 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() @@ -20,21 +23,17 @@ args = parser.parse_args() #SET THIS TO YOUR DEVICE -if args.device: - device = InputDevice('/dev/input/event6') - device = InputDevice('/dev/input/'+ args.device if args.device else 'event7') -# width = 80 -# height = 30 +touchpad_x_max = 1224 +touchpad_y_max = 804 + +max_x = 1920 +max_y = 1080 -width = 160 -height = 60 x = 0 y = 0 -mat = [ [' ']*width for i in range(height)] - def get_xy_coords(e): #you may need to change this number here; i don't know if e.code == 53: @@ -50,19 +49,23 @@ def mapFromTo(x,a,b,c,d): y=(x-a)/(b-a)*(d-c)+c return y +x_pos =0 +y_pos =0 -def draw(mat): - os.system('clear') - for i in mat: - for j in i: - print(j, end='') - print() - # time.sleep(20) - +mouse_controller = mouse.Controller() for event in device.read_loop(): + #rows, cols = stdscr.getmaxyx() get_xy_coords(event) - if event.code == 54: - mat[math.floor(mapFromTo(y,0,804,0,height-1))][math.floor(mapFromTo(x,0,1224,0,width-1))] = '#' - # mat[mapFromTo(y,0,804,0,height-1)][mapFromTo(x,0,1224,0,width-1)] = '#' - draw(mat) + 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) +