Mercurial > code > home > repos > wheel
diff usb_wheel_to_scroll.py @ 0:63a872056503 default tip
start
author | drewp@bigasterisk.com |
---|---|
date | Sat, 25 Feb 2023 15:29:18 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usb_wheel_to_scroll.py Sat Feb 25 15:29:18 2023 -0800 @@ -0,0 +1,28 @@ +from pynput.mouse import Button, Controller +import evdev + +# to stop knob from setting volume: + +# xinput list +# ↳ HID 8808:660c Keyboard id=17 [slave keyboard (3)] + +# xinput disable 17 + +devices = [evdev.InputDevice(path) for path in evdev.list_devices()] +for device in devices: + if device.name == 'HID 8808:660c Keyboard': + break +else: + raise ValueError('not found') + +device = evdev.InputDevice(device.path) +mouse = Controller() + +scroll_per_step = 2 + +for event in device.read_loop(): + if event.value == 1: + if event.code == 114: + mouse.scroll(0, 1 * scroll_per_step) + elif event.code == 115: + mouse.scroll(0, -1 * scroll_per_step)