I'm trying to remap my mouse buttons, two side ones and middle click to 4,5,6 keys on my keyboard,found some guides but I'm very new to Ubuntu and linux in general, I tried to do that for a few days now but to no avail.. Could someone guide me through that or point me to some comprehensive guide that a noob could follow? Any help will be appreciated.
There are basically two approaches to this problem:
- Bind an action to the mouse button and fake a key press
- Map the mouse button's scancode to a different keycode
The latter only works if the input driver reports a scancode for the specific button. All mice I own report scancodes for all buttons except the scroll wheel.
I personally prefer remapping the scancode, so I'll only explain that method.
Remapping mouse button's scancode to different keycode
This is more or less the same procedure as I described here.
sudo evtest (you may have to install
evtest first) and select your mouse. Press the buttons you want to remap (if you don't see any output, press Ctrl+C and repeat the process until you found your mouse). The output should contain lines like the following:
Event: time 1558613958.149431, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90004 Event: time 1558613958.149431, type 1 (EV_KEY), code 275 (BTN_SIDE), value 1 Event: time 1558613958.149431, -------------- SYN_REPORT ------------
The first line tells us the scancode (in my case
90004), the second line reports the currently mapped keycode (in my case
BTN_SIDE). Write down the scancodes of all mouse buttons you want to remap.
Now run the following command, where eventX is the one you chose when using
grep "" /sys/class/input/eventX/device/id/*
This tells you bustype, vendor, product and version of your mouse. In my case, the output is:
/sys/class/input/event7/device/id/bustype:0003 /sys/class/input/event7/device/id/product:4102 /sys/class/input/event7/device/id/vendor:062a /sys/class/input/event7/device/id/version:0110
Now create the following file:
evdev:input:b[bustype]v[vendor]p[product]e[version]* ID_INPUT_KEY=1 KEYBOARD_KEY_[scancode]=4 KEYBOARD_KEY_[scancode]=5 KEYBOARD_KEY_[scancode]=6
- [bustype], [vendor], [product] and [version] are the ones obtained in the previous step with letters converted to uppercase
- [scancode] are the ones from the first step with letters converted to lowercase
evdev:...line has no preceding space
KEYBOARD_KEY...lines have exactly one preceding space
The file would look like this for my mouse:
evdev:input:b0003v062Ap4102e0110* ID_INPUT_KEY=1 KEYBOARD_KEY_90003=4 KEYBOARD_KEY_90004=5 KEYBOARD_KEY_90005=6
sudo systemd-hwdb update and reboot.