Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 Spacebar and I want to map the alt (right), or controlkey to emit a space character? I am running Ubuntu 11.10

share|improve this question

You could use xmodmap to remap one of the keys. First, run xev and press the button you want to remap (e.g. alt). Make a note of the keycode. Then map it to space:

xmodmap -e 'keycode 108 = KP_space'

Replace 108 with the keycode you found in xev. On my keyboard, the right alt is keycode 108. At this point when you press the right alt, it will result in a space but it is still pressing alt as well. You need to remove the old map. In my case, since I modified the Alt_R, when I type xmodmap I see:

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        KP_Space (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

Which shows that KP_Space results in "mod1", which is alt. To remove KP_Space from mod1 (which will stop your alt button from functioning as an alt button), type

xmodmap -e 'remove mod1 = KP_Space'

You'll have to run the xmodmap commands at login, so you should look into the ways of doing that (e.g. ~/.Xmodmap)

share|improve this answer
Hi! I did everything as you told me. On my keyboard right alt is keycode 180, too. When I run xev and press alt, I got listed some information. If I understood correctly, then I need to type: xmodmap -e 'keycode 108 = KP_space' But, nothing is happening. I am getting some information listed again, and he waits to be put new value. Could you please tell me what I'm not doing correctly?! Thanks – Sinisa Mar 24 '12 at 6:47
Dumb question, but did you close xev before entering in xmodmap -e 'keycode 108 = KP_space'? That's supposed to be entered into a terminal (xev is only used to discover the correct keycode, and once you know it you can close xev). If you get some information returned from xmodmap, please copy and paste it here. – pestilence Mar 26 '12 at 15:12
Whoops! Sorry! Now everything is OK. Thank you! – Sinisa Apr 11 '12 at 15:21
Shouldn't it be space not KP_Space? – Sparhawk Apr 12 '13 at 10:11
@Sparhawk you are right. It might depend on the version. – Bhargav Nanekalva Jul 24 '15 at 18:20

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.