3 # Purpose: switch caps to control key and vice versa for linux console and X
4 # Authors: grml-team (grml.org), (c) Matthias Kopfermann <maddi@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Don Nov 23 22:32:29 CET 2006 [mika]
8 ################################################################################
10 if . /etc/grml/script-functions ; then
11 check4progs xmodmap loadkeys dumpkeys || exit 1
13 . /etc/grml/lsb-functions || ( alias einfo=echo ; alias eerror=echo; alias eend=echo )
16 autoload -U colors ; colors
18 if [[ -z $DISPLAY ]] ; then # test if X is not running when calling us
19 if [[ $UID != 0 ]] ; then # test if user root did invoke this command
20 eerror "As of Linux 2.6.15 you need root permissions for changing"
21 eerror "the keyboard on console using loadkeys for security reasons."
22 eerror "Run this program with root permissions. Exiting." ; eend 1
25 dumpkeys | grep -q '^keycode 58 = Caps_Lock' && \
26 ( einfo "caps-ctrl - switching caps lock and control key."
29 keycode 58 = `repeat 15 echo -n 'Control '`
30 keycode 29 = `repeat 7 echo -n 'Caps_Lock '`
35 einfo "caps-ctrl - switching caps lock and control key."
38 keycode 58 = `repeat 15 echo -n 'Caps_Lock '`
39 keycode 29 = `repeat 7 echo -n 'Control '`
44 else # running under X
46 einfo "caps-ctrl - switching caps lock and control key."
47 einfo "If you notice errors, please make sure the xmodmap you have is right"
48 einfo "or use e.g. \"setxkbmap us\" beforehand."
49 xmodmap -pke | grep 'Caps_Lock' > /dev/null || (
51 keycode 66 = Caps_Lock
56 remove Lock = Caps_Lock
57 remove Control = Control_L
58 !remove Control = Control_R
60 keysym Control_L = Caps_Lock
61 keysym Caps_Lock = Control_L
62 !keysym Control_R = Caps_Lock
63 !keysym Caps_Lock = Control_R
66 add Control = Control_L
67 !add Control = Control_R
71 fi # end of test if X or console is used
73 ## END OF FILE #################################################################