6

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:

  1. Use the command xev -event keyboard to get keycodes for the keys I want to swap.

    • For the Fn key, it gave keycode 151 (keysym 0x1008ff2b, XF86WakeUp)
    • For the left Ctrl key, it gave keycode 37 (keysym 0xffe3, Control_L)
  2. Generate the current keycode map and store into a text filed named ".Xmodmap" with the command xmodmap -pke > .Xmodmap in my root directory.

  3. Open ".Xmodmap" file with a text editor

    • Used VS Code using code .Xmodmap command.
  4. 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
      
  5. Save the ".Xmodmap" file.

  6. 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 Ctrl key, it gives
    KeyRelease 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 Fn key, it gives
    KeyRelease 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?

0 Answers0