Don't understand german? Read or subscribe to my english-only feed.

Switch behaviour of Capslock

On my happy hacking keyboard the control-key is located where you “usually” find the caps-lock key. My new laptop (Samsung X20) has a function-key at the left side and next to it (on the right side of it) the control-key. I often misplaced my fingers and as I like the caps-lock-is-control-key-setup I modified the setup using xmodmap. But it sucks if you don’t have the same setup on pure console, therefore I used the well known tool loadkeys to modify this as well. But switching between caps-lock-is-caps-lock and the “original setting” (for capitalization) sucks. Especially because “setxkbmap -option caps:shift” and “setxkbmap -option ctrl:nocaps” are not reliable enough. :-/ And whereas documentation for switching caps-to-ctrl exists you probably won’t find it for the other way around. So I wrote a small script namend caps-ctrl which automatically finds out whether it’s running in X or on console and switches the current setup to “the another one”:

#!/bin/sh
if [ -z $DISPLAY ] ; then
 if [ $UID != 0 ] ; then
   echo 'Sorry, you need root permissions for running $0 on console
using loadkeys. Run this program with root permissions. Exiting.'
   exit -1
 fi
 dumpkeys | grep -q '^keycode  58 = Caps_Lock' && \
 ( echo 'Caps lock mapped to shift-function. Switching caps lock key to control key.'
   echo 'keycode 58 = Control Control Control Control Control Control Control' | loadkeys
 ) ||
 ( echo 'Caps lock mapped to control-function. Switching caps lock key to shift key.'
   echo 'keycode 58 = Caps_Lock Caps_Lock Caps_Lock Caps_Lock Caps_Lock Caps_Lock Caps_Lock' | loadkeys
 )
else
 xmodmap -pm | grep -q 'control.*Caps_Lock' && \
 ( echo 'Caps lock mapped to control-function. Switching caps lock key to shift key.'
   xmodmap -e 'add lock = Caps_Lock'
   echo 'clear Lock
         keycode 66 = Shift_Lock
         add Lock = Shift_Lock' | xmodmap -
   echo 'Problems? Try to run 'setxkbmap -option caps:shift' manually.'
 ) ||
 ( echo 'Caps lock mapped to shift-function. Switching caps lock key to control key'
   xmodmap -e 'keycode 66 = Caps_Lock'
   xmodmap -e 'remove lock = Caps_Lock' -e 'add control = Caps_Lock'
   echo 'Problems? Try to run 'setxkbmap -option ctrl:nocaps' manually.'
 )
fi

As there are some more people out there who like the caps-lock-is-control behaviour (hey jimmy!) I put the script into the package grml-scripts and it will be part of the next grml-release.

Comments are closed.