/keyremapper-rs

A rust library to enable AHK like flexible key remapping for Linux.

Primary LanguageRustMIT LicenseMIT

keyremapper-rs

A Rust library to help enable AHK like flexible key remapping.

What it is and what it provides

At a high level, it allows to "steal" input events from specific input devices (keyboards, pointing devices, etc) using evdev, modify with your rust code and inject using /dev/uinput, which allows to create a versatile mapping.

  • Unlike AHK, KeyRemapper is a library. Your "script" is a full rust program.

  • Unlike AHK, KeyRemapper can distinguish different input devices, and allows you to handle different devices differently.

  • This library provides a function to get the active window information. Use this to use different mappings for different apps.

Prerequisite

1. Gain access to /devn/input/* and /dev/uinput

# Add self to the input and uinput groups
sudo usermod -aG input $USER 
sudo groupadd uinput
sudo usermod -aG uinput $USER

# See https://github.com/chrippa/ds4drv/issues/93
echo 'KERNEL=="uinput", SUBSYSTEM=="misc", MODE="0660", GROUP="uinput"' | sudo tee /etc/udev/rules.d/90-uinput.rules

# This seems to be needed because uinput isn't compiled as a loadable module these days.
# See https://github.com/chrippa/ds4drv/issues/93#issuecomment-265300511
echo uinput | sudo tee /etc/modules-load.d/uinput.conf

Then reboot.

See also:

2. Install dependeencies

  • sudo apt install -y libappindicator3-dev libgtk-3-dev libevdev-dev libudev-dev

Samples

Note: all the following samples will remap only certain kinds of keyboards specified by the regex DEVICE_RE in them. In order to use them with your input devices, use the --match-device-name option and provide a regex that matches your input device. You can find the device name and the vendor/product ID of your device using the evsniff sample.

If you need to disdistinguish different devices with the same name, provide a regex mathing the vendor/product ID with the --match-id option.

  • Install all the samples: run ./install-examples.sh

  • keyboard-remapper

    • For the following 3 keyboards:

    • Adds various shortcuts using ESC.

    • Creates an extra uinput device to inject mouse wheel events. e.g. ESC + H, J, K and L for virtucal and horizontal scroll.

    • App specific remap -- on Chrome, use F5/F6 as BACK/FORWARD. This can be done using keyremapper::ui::WindowInfo::from_active_window().

  • shortcut-remote-remapper for https://www.amazon.com/gp/product/B01NC2LEYP

  • trackpoint-speedup Speed up Thinkpad trackpoint. I can never figure out how to easily do it.

  • evsniff Kind of like evtest(1) but reads from all the devices at once. Use this to figure out the device name and its vendor/product IDs.

TODOs

  • Better error handling (chain, stacktrace, etc?)
  • Better APIs.

Links