Longtime no post on my blog , and i just brought a nice USB keyboard from local store.

But it really sucks each time i plug in my USB keyboard. Since X11 is on the hood , my customized key mapping will fail to process unless i relaunch corresponding command set in ~/.xinitrc , namely `setxkbmap` in this case.

Digging a bit on Google , i found it possible to monitor USB device changes through well-defined dbus interfaces provided by Hal:


But since i adores perl , here i will demonstrate an equivalent and functional script written totally in perl , it’s available for downloading here:


Script preview can be found below , now i just unplugged my USB mouse and re-plugged it in , which instantaneously triggered huge outputs in my console:

Redistribution is allowed , and feel free to post a comment here , it’s welcomed ;-P

Do we really need the CapsLock Key , i don’t. Maybe somebody would rather take this as a design fault.

Mapping to CTRL key is a good taste , it’s much more nearer to your finger , thus more convenient.

For Windows System , a easy solution would be save the entries below and import it to window register:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]”Scancode Map”=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

UNIX is rather simple , for Xorg system , simply try launch this command after Xorg initial process:

setxkbmap -option ctrl:nocaps &

A happy keyboard hacker could play around with standard UNIX keyboard mapping file , which is stored in /usr/share/keymaps/

Remember to put a backup first , before any changes took place:


Extract and edit us.map , and seek for the entry about Caps_Lock

Modify this

keycode  58 = Caps_Lock
Well , of course do a substitution , and we got it.
To  keycode  58 = Control
Now put it back to /usr/share/keymaps/i386/qwerty/us.map.gz , run as root to load new keyboard mappings :
# loadkeys us
See it , easy huh ?