Monday, September 10, 2012

Remap Keyboard: Assign not working keys to different keys


Laptop keyboards are not always the greatest quality, and after some time it might have a key or few keys not working. When they are vital keys, it really is a game stopper. In my case I had the "BackSpace" and "Enter/Return" keys not working.
"PgUp" and "PgDn" are handy but you can go without them. So I decided to give the "PgUp" key the BackSpace function, and the "PgDn" the Enter/Return function.
Here is How:



First find the Keycode:

In a terminal screen, type xev to find key codes. type "BackSpace", "Return/Enter", "PgUp", "PgDn", and then close the xev function.
You should see following:



KeyPress event, serial 36, synthetic NO, window 0x5000001,
    root 0xc3, subw 0x0, time 43597834, (1344,260), root:(1394,1390),
    state 0x10, keycode 22 (keysym 0xff08, BackSpace), same_screen YES,
    XLookupString gives 1 bytes: (08) "
    XmbLookupString gives 1 bytes: (08) "
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x5000001,
    root 0xc3, subw 0x0, time 43595123, (1344,260), root:(1394,1390),
    state 0x10, keycode 36 (keysym 0xff0d, Return), same_screen YES,
"   XLookupString gives 1 bytes: (0d) "
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x5000001,
    root 0xc3, subw 0x0, time 43601034, (1344,260), root:(1394,1390),
    state 0x10, keycode 112 (keysym 0xff55, Prior), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x5000001,
    root 0xc3, subw 0x0, time 43602156, (1344,260), root:(1394,1390),
    state 0x10, keycode 117 (keysym 0xff56, Next), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

You can see here the keycode and key description / function.

Using the following command at the command line will remap the keys.

xmodmap -e 'keycode 112 = BackSpace'
xmodmap -e 'keycode 117 = Return'

Making this permanent so it will be set every start-up:
Export the new keymapping to a file in the home directory. (ex .mykeymap) Use a dot as first character in the filename to make it hidden.

xmodmap -pke > .mykeymap

Now add the following to your startup.

 








No comments:

Post a Comment

Please be courteous, even if you do not share the same view.