How do I change my control or alt key to emit a space key event?

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like