Skip to content

Instantly share code, notes, and snippets.

@versusvoid
Last active October 24, 2021 04:14
Show Gist options
  • Save versusvoid/e3c30e75c91354fb4d8cb1734490ad76 to your computer and use it in GitHub Desktop.
Save versusvoid/e3c30e75c91354fb4d8cb1734490ad76 to your computer and use it in GitHub Desktop.
Scroll with Microsoft Natural® zoom slider
# installed in /etc/udev/hwdb.d/
# after installing run
# $ sudo udevadm hwdb --update
# $ sudo udevadm control --reload
# Microsoft Natural Ergonomic Keyboard 4000
evdev:input:b0003v045Ep00DB*
KEYBOARD_KEY_c022d=scrollup # zoomin
KEYBOARD_KEY_c022e=scrolldown # zoomout
#!/usr/bin/env python3
# start as root (I run as systemd service)
# or from group with access to input devices
import sys
import glob
# python-libevdev package on ArchLinux
import libevdev
for f in glob.glob('/dev/input/event*'):
f = open(f, 'rb')
d = libevdev.Device(f)
if 'Microsoft Natural' in d.name and d.has(libevdev.EV_REL.REL_HWHEEL):
break
f.close()
else:
print("Can't find Microsoft Natural device with wheel event")
sys.exit(1)
fake_mouse = libevdev.Device()
fake_mouse.name = 'fake mouse'
fake_mouse.enable(libevdev.EV_REL.REL_WHEEL)
uinput = fake_mouse.create_uinput_device()
for e in d.events():
fake_events = []
if e.matches(libevdev.EV_KEY.KEY_SCROLLUP) and e.value in (1, 2):
fake_events.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, value=1))
if e.matches(libevdev.EV_KEY.KEY_SCROLLDOWN) and e.value in (1, 2):
fake_events.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, value=-1))
if fake_events:
fake_events.append(libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT, value=0))
uinput.send_events(fake_events)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment