How to remap keyboard keys in ubuntu

Recently I bought a new keyboard, a Genius Luxemate i202, and the only thing that really disappointed me was the fact that it has two Window$ keys, left and right, and no Menu key, that I use a lot. Fortunately, it is fairly simple to remap keyboard keys in Ubuntu. To do it we just have to use an application called Xmodmap, which is a utility for modifying keymaps and pointer button mappings in Xorg. As an example, to make a single keymap for the current session, you just need to open the terminal and enter the following command:
xmodmap -e "keycode 0x86 = Menu"
The command above replaces the Right Window$ key (keycode 0x86) with the Menu key. However, if you want to remap some keys, you want the operating system to remap them every time you use the computer. So, let’s start by creating a file “.Xmodmap” in your user directory. This file will contain all the remapping info that should be loaded every time you boot Ubuntu. As an example, I’ll show you how to do the remapping that I had to do to turn my Right Window$ key into a Menu key. Open the .Xmodmap with a text editor of your choice and enter the following commands:
remove mod4 = Super_R
add mod3 = Super_R
keycode 0x86 = Menu
How did I got to know about this codes and names? I’ll show you. 🙂 To begin, I executed the following command:
xmodmap -pm
which has given-me the following information:
shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)
The left and right Window$ keys are called Super_L and Super_R on linux. As you can see, the Super_R key is associated with the modifier key mod4 and has the code 0x86. So, what I did next was dissociate it from mod4 modifier key (remove mod4 = Super_R), and then assign it to modifier key mod3 (add mod3 = Super_R), which is doing nothing. Then I remaped it to become the Menu key (keycode 0x86 = Menu). Easy, right? 🙂 If you want to test the configuration written in your .Xmodmap file without rebooting, just run the following command:
xmodmap .Xmodmap
You can do the same to any key that you which to change. If you have access to the computer of some friend you can even use this to make a quick and easy prank 😛 
If you want to find out the keycode from a specific key, you can install and run xev:
sudo apt-get install xev
xev
Hope this was useful for you! 🙂
 
Take care! 🙂

Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! 🙂
 
Donate


  • Facebook
  • Twitter
  • Google Plus
  • LinkedIn
  • Reddit
  • Delicious
  • StumbleUpon
  • Digg
  • RSS
  • Email
  • Print