ThinkPad Function-Key Mapping to Toggle Touchpad in Ubuntu 18.04 (Xorg Edition)
This is a follow-up to my existing blog post on setting a function-key to toggle the touchpad in Ubuntu 18.04 on the ThinkPad X1 Carbon (5th-Gen).
The instructions worked for awhile, but differences between Wayland and Xorg eventually led to it breaking in kernel version 4.15.0-47-generic
. I suspect it has something to do with Xorg’s limit on keycodes above 255.
Here are updated instructions for getting a function-key to toggle the touchpad in Ubuntu 18.04 for Xorg!
Find the event device for function-keys
First, we need to find out the device that handles the function-keys on the ThinkPad keyboard. On my system, it’s called "ThinkPad Extra Buttons"
.
To get more information about the device, run cat /proc/bus/input/devices
. A block for "ThinkPad Extra Buttons"
should appear among the list of devices:
Take note of event6
. It’ll be used in the next section.
Find the scancode for a function-key
In order to remap our function-key, we’ll need its scancode. This is a signal the keyboard sends to the computer indicating it has been pressed.
To get the scancode, we use a utility named evtest
on our event device from the previous step, event6
. Run sudo evtest /dev/input/event6
:
While evtest
is running, press the function-key. In my case, I wanted to remap the “keyboard” function-key (Fn
+F11
):
Take note of the value 49
. This is the scancode!
Create a custom hwdb
keyboard mapping
Note: It might be worth some time to read up about hwdb
.
Armed with the scancode, we create a custom hwdb
configuration to map it to our desired keycode. Create a new file in /lib/udev/hwdb.d/
(I named it 90-custom-keyboard.hwdb
, but it can be anything):
The first line is a match-string for our device, "Thinkpad Extra Buttons"
. The left-hand side of second line is the scancode for our key appended to "KEYBOARD_KEY_"
. The event, f21
, is the “toggle touchpad” keycode.
Note: I found my device match-string and “toggle touchpad” keycode in /lib/udev/hwdb.d/60-keyboard.hwdb
.
After saving the new file, run sudo udevadm hwdb --update
.
Finally, restart the system and log back in. If things are set up properly, the function-key should toggle the touchpad!
Conclusion
The following links were extremely helpful in getting this working:
- Slow & Steady Blog: Linux keymapping with udev hwdb
- ThinkPad Scripts: Configuring Additional Hardware Keys
- MOHAN43U’s Blog: Howto remap keyboard keys in Linux
Questions? Suggestions? Corrections? Leave me a comment. Cheers!