annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
drewp@bigasterisk.com
parents:
diff changeset
1 from pynput.mouse import Button, Controller
drewp@bigasterisk.com
parents:
diff changeset
2 import evdev
drewp@bigasterisk.com
parents:
diff changeset
3
drewp@bigasterisk.com
parents:
diff changeset
4 # to stop knob from setting volume:
drewp@bigasterisk.com
parents:
diff changeset
5
drewp@bigasterisk.com
parents:
diff changeset
6 # xinput list
drewp@bigasterisk.com
parents:
diff changeset
7 # ↳ HID 8808:660c Keyboard id=17 [slave keyboard (3)]
drewp@bigasterisk.com
parents:
diff changeset
8
drewp@bigasterisk.com
parents:
diff changeset
9 # xinput disable 17
drewp@bigasterisk.com
parents:
diff changeset
10
drewp@bigasterisk.com
parents:
diff changeset
11 devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
drewp@bigasterisk.com
parents:
diff changeset
12 for device in devices:
drewp@bigasterisk.com
parents:
diff changeset
13 if device.name == 'HID 8808:660c Keyboard':
drewp@bigasterisk.com
parents:
diff changeset
14 break
drewp@bigasterisk.com
parents:
diff changeset
15 else:
drewp@bigasterisk.com
parents:
diff changeset
16 raise ValueError('not found')
drewp@bigasterisk.com
parents:
diff changeset
17
drewp@bigasterisk.com
parents:
diff changeset
18 device = evdev.InputDevice(device.path)
drewp@bigasterisk.com
parents:
diff changeset
19 mouse = Controller()
drewp@bigasterisk.com
parents:
diff changeset
20
drewp@bigasterisk.com
parents:
diff changeset
21 scroll_per_step = 2
drewp@bigasterisk.com
parents:
diff changeset
22
drewp@bigasterisk.com
parents:
diff changeset
23 for event in device.read_loop():
drewp@bigasterisk.com
parents:
diff changeset
24 if event.value == 1:
drewp@bigasterisk.com
parents:
diff changeset
25 if event.code == 114:
drewp@bigasterisk.com
parents:
diff changeset
26 mouse.scroll(0, 1 * scroll_per_step)
drewp@bigasterisk.com
parents:
diff changeset
27 elif event.code == 115:
drewp@bigasterisk.com
parents:
diff changeset
28 mouse.scroll(0, -1 * scroll_per_step)