I've installed Lubuntu on an old Mac and found out that by default the Command key is mapped as Super and Control and Control.
My muscle memory on this device is to use Command key as a primary control key, so I wanted to remap it for ease of use with Lubuntu. Lubuntu is a lightweight distribution of Linux, designed for older devices. It comes with the LXQT desktop management. This is the part that makes the key remapping a bit trickier. Through some trial and error I have found a way to remap the keys so sharing the know how in case it helps others.
Update LXQt Shortcut
The first tricky part of the set up is the preset shortcuts that Lubuntu installs, namely the Super key is configured to show the main menu. The shortcut need to be updated first, so it doesn't interfere with the remapping. To do that:
- Click on the Main Menu
- Navigate to Preferences > LXQt Settings > Shortcut Keys
- Locate a shortcut for Show/hide main menu
- Modify the shortcut, updating it to a key combination, for example Control + M
- Note do not update it to either Super or Command one key shortcut, as that will make the remapping hard to work with
Update XModMap
The core of Lubuntu is Ubuntu/Debian and uses XmodMap to map the keys, so we can use it to remap the keys.
- Create a file
.xmodmapin the home directory - Add remapping instructions into the file and save
- Run
xmodmap ~/.xmodmapor/usr/bin/xmodmap ~/.xmodmapin the terminal to activate your remapping - Test your
ControlandCommandkeys and the combination shortcuts
This is the code that worked for me in the end. I have a keyboard with one Control and two Command/Super keys, which are remapped to two Control and one Super key. So running this remapping twice, will throw an expected error in the terminal, as Super_R cannot be cleared a second time after it has been cleared once.
clear control
clear mod4
remove mod4 = Super_L NoSymbol Super_L Hyper_L Super_R NoSymbol Super_R
remove control = Control_L Control_R Control_L NoSymbol Control_L
keycode 37 = Super_L
keycode 206 = Control_L
keycode 133 = Control_R
keycode 134 = Control_L
add control = Control_L
add control = Control_R
add mod4 = Super_L
Helpful Resources
Helpful Utilities
xevcommand shows the box that will detect key codes; renders a lot of information about each keystrokexinput listcommand shows the list of devices, get theKEYBOARD_IDfrom the list, then runxinput test $KEYBOARD_IDthis will render the key code of the hit keysetxkbmap -optioncommand will reset the mapping back to default; helpful to do a quick reset without a rebootxmodmap -pkecommand will show all current mappings for the keyboardxmodmap -pke | grep -P '(Control|Super)'command will show specific mappings for the Control and Super keysxmodmap -pmcommand will show modifier keys
Load Custom Map on Reboot
Once the XModMap is configured and working, but it's not quite the end because the settings will not stick on the reboot. Adding the command to .profile or .bashrc may not work until you launch a terminal. To solve this problem, we can utilize the Lubuntu's LXQt autostart configuration to execute our command.
- Click on the Main Menu
- Navigate to Preferences > LXQt Settings > Session Settings
- Inside the dialog box, click on Autostart
- Click Add to add a new command
- Give command the name xmodmap and add
/usr/bin/xmodmap ~/.xmodmapas a command - Save and close
Now the code should load on boot time and your keyboard keys should be remapped.
Happy coding.