~/git/blog

My brain-dump of random code/configuration.

16 Oct 2013

Permanent Remap Keys in X11

Because my shift key got broken, I remapped Caps Lock to Shift using xmodmap:

remove Lock = Caps_Lock
keysym Caps_Lock = Shift_L
add Shift = Shift_L

However these settings got sometimes lost. (ex: after the driver was reloaded after suspend). Finally I found event_key_remap patch from here, which allows to permanently redefine keys in the xorg.conf.

To apply the patch under archlinux simply install xf86-input-evdev-remap from AUR:

yaourt -S xf86-input-evdev-remap

To track down the key, you want to remap use xev on the terminal. Just type the wanted keys a few times. The output will be something like the following:

KeyRelease event,  serial 33,  synthetic NO,  window 0x1e00001,
    root 0x8e,  subw 0x0,  time 5672767,  (611, 262),  root:(613, 288),
    state 0x1,  keycode 50 (keysym 0xffe1,  Shift_L),  same_screen YES
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

The interesting value here is the keycode. Use this code to build your final xorg.conf. In my case this was:

#/etc/X11/xorg.conf.d/10-kb-layout.conf
Section "InputClass"
    Identifier             "Keyboard Defaults"
    MatchIsKeyboard        "yes"
    Option                 "XkbLayout" "de"          # Replace this with your layout
    Option                 "event_key_remap" "58=50" # Caps Lock Key = Shift
EndSection

Archived comments

Imported from Disqus, which this blog used before switching to giscus.

diana

hi, im having a problem with my keyboard the enter key is not working im using samsung sf410, windows 7 64bit .. im trying to replace left shift key as an enter key i have keyTwek install on my machine it did a great job, i have successfully change the left shift key into enter key but then problem is i just installed linux on my system which is cd bootable, every time i will try to use the linux i need to used enter key which in this case the remapped key which is left shift key to enter key is not working.. i was thinking if there is a permanent remapping appliction i could used so i can have an enter key?.

thanks
Diana
diana_degamo@yahoo.com

Mic92

Your comment get lost somehow. the same procedure should be also working for `enter`.
In case somebody else has this problem, the key code on my keyboard for enter is 50.