Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a laptop with a broken space bar and I want to map the right alt or control keys to emit a space character. I am running Ubuntu.

share|improve this question
up vote 2 down vote accepted

Use xmodmap:

xmodmap -e 'keysym Control_R = KP_Space'

this will allow you to use the left control key as a space key.

share|improve this answer
Probably xmodmap -e 'Control_R = KP_Space'. – whitequark Feb 1 '10 at 5:14
whoops, didn't see "right" on first read, thanks :) – John T Feb 1 '10 at 5:16
Thanks guys, for whatever reason here it had to be: xmodmap -e 'keysym Alt_R = KP_Space' But otherwise it works well! – Jotham Feb 1 '10 at 5:16
Wasn't sure if you preferred alt or control, but you're most welcome! :) – John T Feb 1 '10 at 5:18
Also might be worth noting. I ended up using wanting to bind space to a different key (in this case the period). To find out the appropriate keysym i ran xev and tapped the period (0x2e here). – Jotham Feb 1 '10 at 9:43

I had the same problem with a broken spacebar. This was the simplest result I found, but at first using the Alt_R option didn't work because I had followed a different tutorial and messed up the binding of my right-alt key.

To find out which keysym to use just run 'xev' and press the key that you want to remap to the spacebar function. That will give you the keysym (in my case it was 0xfe03). Then in a terminal type: xmodmap -e 'keysym [keysym you found] = KP_Space' and hit 'Enter' (don't type the brackets either, just your keysym).

You can remap more than one key in this way, for example I never use the right windows key (keysym Super_R) so I did the same for that one and now I have two adjacent keys that both act as a spacebar. Hope this helps someone else to save around 30 quid buying a new laptop keyboard like it did for me!

BIG HOWEVER! However, I just found that you will need to do this every time you login UNLESS you create a new file and add it to startup. Additionally, you will note that I am using the keycode rather than keysym. This is because the keysym could change if you or another program changes it. The keycode stays the same.

Here's how:

  1. Create a simple text file and call it something like xmodmap (no extension required).

  2. On the first line enter #! /bin/bash

  3. On the next line enter your modification code, eg xmodmap -e 'keycode 108 = KP_Space' [Note that keycode 108 on my keyboard is the right alt key - use xev to check yours]

  4. Repeat number 3. for however many other mappings you need, with one on each line

  5. Save the file then make it executable. Eg if you saved it as modmap in your default folder, open up a terminal and type chmod 777 xmodmap

  6. Now go to System->Preferences->Startup Applications and click Add. Browse to your saved xmodmap file, click Open, then click Add. Close it, and now when you next log in your mappings will work automatically!

share|improve this answer
You probably want chmod 755, not 777, unless you really want to make it easy for everyone to edit it and have any command they want be run as part of your desktop startup. – alanc Jun 23 '11 at 5:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.