Using Xmodmap to map one key to another

So, everybody having a good holiday?? As for me, I got unlucky with my super sleek and shiny laptop and its motherboard got fried. So, for quite some time I was relegated to using a laptop which

(i) had a Spanish keyboard, on top of which I was using German and English layouts (oh yes, even for programming ;-)), and

(ii) had the period/colon key missing (it had been ripped off), so I was using another keyboard connected via a USB port to type my periods and colons whenever they came up. And no, I could not only use the USB keyboard because that one in turn had some keys not in the best working order (!!! wait, it gets better soon !!!)

After bearing with all this for quite some time, I thought there has to be some way I can map the period/colon key to one of the keys I am not using, for example Pause, F12 etc., and do away with the additional USB keyboard, and thus make things a little better. So I finally stumbled upon Xmodmap, which my Ubuntu was pre-equipped with, of course, and figured out a simple way to accomplish the task at hand.

Use the following at the command line:

xmodmap -e "keysym Pause = period"
xmodmap -e "keysym F12 = colon"

And you’re done! Now Pause prints the period and F12 prints the colon, no matter whether you are using the German, English or Spanish layout. I guess if you put “period colon” together then the later character will be printed with shift, but I didn’t experiment with that.

I tried putting these lines in my .xinitrc file and then in my .profile, but for some reason it doesn’t seem to be running automatically when the computer boots. For the time being I am having to do it manually every ime the computer starts afresh.

Here is a list of all the “keysym” codes you can use with Xmodmap!

There you are – happy Xmodmapping šŸ˜‰


One thought on “Using Xmodmap to map one key to another

  1. I have the problem that the US keyboard has less keys, and I use the dvorak es map, so there is no key for , but there is a key with | and \ that I want to map to .

    Using xev I get the keycode of the key to be 51, so the first map is easy

    # key to <
    xmodmap -e 'keycode 51=0x3c'

    # but how can I map the same keycode with a modifier (shift)

    I hope you can help me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s