Skip to content

Instantly share code, notes, and snippets.

@versusvoid
Last active October 24, 2021 04:14
Show Gist options
  • Select an option

  • Save versusvoid/e3c30e75c91354fb4d8cb1734490ad76 to your computer and use it in GitHub Desktop.

Select an option

Save versusvoid/e3c30e75c91354fb4d8cb1734490ad76 to your computer and use it in GitHub Desktop.

Revisions

  1. versusvoid revised this gist Oct 24, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 61-microsoft-4000.hwdb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # installed in /lib/udev/hwdb.d/
    # installed in /etc/udev/hwdb.d/
    # after installing run
    # $ sudo udevadm hwdb --update
    # $ sudo udevadm control --reload
  2. versusvoid created this gist May 10, 2021.
    9 changes: 9 additions & 0 deletions 61-microsoft-4000.hwdb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # installed in /lib/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
    33 changes: 33 additions & 0 deletions scroll-mapper.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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)