2

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

1 Answer 1

3

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)
mod3
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)

5
  • 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, 2012 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, 2012 at 15:12
  • Whoops! Sorry! Now everything is OK. Thank you!
    – Sinisa
    Apr 11, 2012 at 15:21
  • 1
    Shouldn't it be space not KP_Space?
    – Sparhawk
    Apr 12, 2013 at 10:11
  • @Sparhawk you are right. It might depend on the version. Jul 24, 2015 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .