~metalune/Dotfiles

50079993c4047b735cd8653939bbdab080c1d607 — metalune 20 days ago 99aaf03
Add sl660 driver
1 files changed, 85 insertions(+), 0 deletions(-)

A sl6602_driver.py
A sl6602_driver.py => sl6602_driver.py +85 -0
@@ 0,0 1,85 @@
from inputs import devices, get_gamepad
from pynput.mouse import Button, Controller
import time
import threading
import os


mouse = Controller()

movement = (0,0)
pressed = (0,0)
scroll_button_down = False
speedy_mode = False
thread = None
acceleration = 5
speedy_acceleration = 10
scroll_acceleration = 1

def get_gamepad_events():
    global movement
    global pressed
    global scroll_button_down
    global speedy_mode

    while 1:
        events = get_gamepad()
        for event in events:
            if event.ev_type == "Absolute":
                if event.code == "ABS_X":
                    if event.state == 128:
                        movement = (0,movement[1])
                    elif event.state == 0:
                        movement = (-1,movement[1])
                    elif event.state == 255:
                        movement = (1,movement[1])
                elif event.code == "ABS_Y":
                    if event.state == 128:
                        movement = (movement[0],0)
                    elif event.state == 0:
                        movement = (movement[0],-1)
                    elif event.state == 255:
                        movement = (movement[0],1)
            elif event.ev_type == "Key":

                if event.code == "BTN_C":
                    if event.state:
                        mouse.press(Button.left)
                    else:
                        mouse.release(Button.left)
                elif event.code == "BTN_SOUTH":
                    if event.state:
                        mouse.press(Button.right)
                    else:
                        mouse.release(Button.right)
                elif event.code == "BTN_EAST":
                    scroll_button_down = event.state
                elif event.code == "BTN_NORTH" and event.state == 1:
                    speedy_mode = not speedy_mode
                    if speedy_mode:
                        os.system("notify-send \"I am speed.\"")
                    else:
                        os.system("notify-send \"I am slow.\"")


thread = threading.Thread(target=get_gamepad_events)
thread.start()

while 1:

    if scroll_button_down:
        mouse.scroll(movement[0] * scroll_acceleration, -movement[1] * scroll_acceleration)
    else:
        # MOVE MOUSE
        accel = acceleration
        if speedy_mode:
            accel = speedy_acceleration

        if movement[0] != 0 or movement[1] != 0:
            mouse.move(movement[0] * accel, movement[1] * accel)


    time.sleep(0.016)