1 AUTHOR: Tim van der Molen <tbm at home dot nl>
3 LICENSE: GNU Free Documentation License Version 1.2
4 SYNOPSIS: Automatically enabling NumLock when booting LFS and when starting X.
5 DESCRIPTION: See SYNOPSIS.
6 PREREQUISITES: The use of a System V-style booting process.
9 This hint describes how to enable NumLock automatically when LFS is booted and
12 1. ENABLING NUMLOCK WHEN BOOTING LFS
14 We will create a simple boot script that will run setleds to enable NumLock on
15 all ttys. setleds is part of the kbd package which is installed on a default
16 LFS system. You might be happy to know that it can also set CapsLock and
17 ScrollLock. Refer to setleds(1) for more information.
19 Create the boot script:
21 cat > /etc/rc.d/init.d/numlock << "EOF"
24 source /etc/sysconfig/rc || exit 1
25 source $rc_functions || exit 1
27 echo "Enabling NumLock..."
29 for tty in /dev/tty[1-6]; do
30 /usr/bin/setleds -D +num < $tty
36 If you use devfs, you probably want to replace "/dev/tty[1-6]" with
39 Next, make the boot script executable:
41 chmod 0755 /etc/rc.d/init.d/numlock
43 And finally, create a symlink from the /etc/rc.d/rcsysinit.d directory to the
46 ln -s ../init.d/numlock /etc/rc.d/rcsysinit.d/S90numlock
48 2. ENABLING NUMLOCK WHEN STARTING X
50 When started, X disables NumLock for some reason. So let us enable it once
51 again. There are different ways to accomplish this.
55 If you happen to run KDE, you can set NumLock to be enabled per default in
56 Control Center > Peripherals > Keyboard > Advanced.
60 NumLockX allows you to enable and disable NumLock for X. It can be downloaded
61 from <http://freshmeat.net/projects/numlockx/>.
63 If you like it, you can compile and install it:
65 ./configure --prefix=/usr
69 Then add the following line to the beginning of either the ~/.xinitrc,
70 ~/.Xsession or ~/.Xclients file:
76 xsetleds can be considered to be the X equivalent of setleds. It can be
77 downloaded from <http://www.home.unix-ag.org/bmeurer/projects/xsetleds/>.
79 2.4. COMPILING A LITTLE PROGRAM YOURSELF
81 Perhaps the easiest way is to compile a little C program yourself which does
82 nothing more than changing the current state of NumLock. Thus, X disables
83 NumLock and this program enables it again. The source code of this program was
84 taken from an article in the SuSE Support Database at
85 <http://sdb.suse.de/en/sdb/html/cg_x11numlock.html>.
87 Create the C source file:
89 cat > xsetnumlock.c << "EOF"
90 #include <X11/extensions/XTest.h>
91 #include <X11/keysym.h>
95 Display* disp = XOpenDisplay(NULL);
97 if (disp == NULL) return 1;
99 XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock),
101 XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock),
102 False, CurrentTime );
111 gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o xsetnumlock \
112 xsetnumlock.c -lX11 -lXtst
114 Now you have a binary named xsetnumlock. If required, change its ownership and
117 chown root:root xsetnumlock
118 chmod 0755 xsetnumlock
120 Move it to either /usr/bin or /usr/X11R6/bin, whatever you consider more
121 suitable. Then add the following line to the beginning of either the
122 ~/.xinitrc, ~/.Xsession or ~/.Xclients file (assuming you have moved
123 xsetnumlock to /usr/bin; if not, use the appropriate path):
129 Right, that should do it. Enjoy your NumPad.
131 Comments, improvements whatsoever on this hint will be received with a warm
132 welcome at the e-mail address specified in the AUTHOR field above.
135 * Manfred H. Winter <mahowi at gmx dot net> for mentioning the C program from
136 the SuSE Support Database as well as other important improvements of this
138 * Tushar Teredesai <tush at yahoo dot com> for mentioning NumLockX and the KDE
140 * Seth W. Klein <sk at sethwklein dot net> for mentioning xsetleds.
144 * Hint conforms to new format.
145 * Minor text changes.