import functools
import pyudev
from pynput.keyboard import Key
import pynput
from evdev import InputDevice, ecodes
from select import select
import subprocess
SCROLL_UP_COMMAND = "xdotool click --clearmodifiers 4"
SCROLL_DOWN_COMMAND = "xdotool click --clearmodifiers 5"
mouse = pynput.mouse.Controller()
keyboard = pynput.keyboard.Controller()
time1 = 0.2000000
sensitivity = 0
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='input')
monitor.start()
fds = {monitor.fileno(): monitor}
while True:
r, w, x = select(fds, [], [])
if monitor.fileno() in r:
r.remove(monitor.fileno())
for udev in iter(functools.partial(monitor.poll, 0), None):
if not udev.device_node:
break
for name in (i['NAME'] for i in udev.ancestors if 'NAME' in i):
if u'Doomscroller System Multi Axis' in name:
if udev.action == u'add':
try:
dev = InputDevice(udev.device_node)
for event in dev.read_loop():
if sensitivity > 2:
if event.type == ecodes.EV_REL:
if event.value > 0 and event.timestamp() - time1 > 1.91:
subprocess.run(SCROLL_DOWN_COMMAND, shell=True)
elif event.value < 0 and event.timestamp() - time1 > 1.91:
subprocess.run(SCROLL_UP_COMMAND, shell=True)
sensitivity = 0
sensitivity += 1
except Exception as e:
print(f"Error: {e}")
if udev.action == u'remove':
print("Dial Disconnected - Bluetooth")
break