So I've spent a solid couple of hours trying to figure out how to remap a couple of keys on a Lenovo ThinkPad T440p laptop. This article from 2020 got me pretty close. It uses the xmodmap command to generate a text file to simply swap some of the key codes. Below is a summary of the process I followed:
Use the command
xev -event keyboardto get keycodes for the keys I want to swap.- For the
Fnkey, it gavekeycode 151 (keysym 0x1008ff2b, XF86WakeUp) - For the left
Ctrlkey, it gavekeycode 37 (keysym 0xffe3, Control_L)
- For the
Generate the current keycode map and store into a text filed named ".Xmodmap" with the command
xmodmap -pke > .Xmodmapin my root directory.Open ".Xmodmap" file with a text editor
- Used VS Code using
code .Xmodmapcommand.
- Used VS Code using
Swap the appropriate lines.
- Orginally, it was
keycode 37 = Control_L NoSymbol Control_L keycode 151 = XF86WakeUp NoSymbol XF86WakeUp - Which was change to
keycode 37 = XF86WakeUp NoSymbol XF86WakeUp keycode 151 = Control_L NoSymbol Control_L
- Orginally, it was
Save the ".Xmodmap" file.
Use the command "xmodmap .Xmodmap" to remap the keys.
What's weird is that it works just fine for the authors test case (ie, mapping the left-arrow & right-arrow keys to the PgUp & PgDn keys, respectively). Also, when I run the xev -event keyboard command and test the keys, they actually do display the correct changes:
- For the left
Ctrlkey, it givesKeyRelease event, serial 28, synthetic NO, window 0x4400001, root 0x175, subw 0x0, time 12122767, (136,230), root:(253,339), state 0x4, keycode 37 (keysym 0x1008ff2b, XF86WakeUp), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False - For the
Fnkey, it givesKeyRelease event, serial 28, synthetic NO, window 0x4400001, root 0x175, subw 0x0, time 12190541, (377,341), root:(494,450), state 0x0, keycode 151 (keysym 0xffe3, Control_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False
Any suggestions on what's going on here?