1 TITLE: Automatically Enabling NumLock When Booting And Starting X
3 AUTHOR: Tim van der Molen <tbm at home dot nl>
10 Version 1.7 (January 8, 2003)
12 This hint describes how you can have NumLock automatically enabled when you
13 boot LFS and, as X disables it again, enabled once again when you start X.
15 1. ENABLING NUMLOCK WHEN BOOTING LFS
17 To enable NumLock when we boot LFS we will create a boot script. This boot
18 script will use setleds to do the actual enabling. setleds is part of the kbd
19 package which is part of a standard LFS system. It can also set CapsLock and
20 ScrollLock. For more information about setleds, see its man page.
22 The boot script will enable NumLock on the tty's 1 to 12. It does not take
23 start/restart/reload/stop arguments because setleds isn't a daemon; it just
24 enables or disables a LED and then exits again.
26 Type the following to create the boot script:
28 cat > /etc/rc.d/init.d/numlock << "EOF"
31 source /etc/sysconfig/rc
34 echo "Enabling NumLock..."
35 for tty in /dev/tty{1,2,3,4,5,6,7,8,9,10,11,12}; do
36 setleds -D +num < $tty
42 And make it executable:
44 chmod a+x /etc/rc.d/init.d/numlock
46 Next to do, is creating a symlink from the /etc/rc.d/rcsysinit.d directory to
47 the boot script so it is actually invoked when LFS is booted. Type the
50 ln -s /etc/rc.d/init.d/numlock /etc/rc.d/rcsysinit.d/S90numlock
52 2. ENABLING NUMLOCK WHEN STARTING X
54 For some reason, X thinks it is appropriate to disable NumLock when it is
55 started which can be found very annoying. Luckily, there are different ways to
56 have it enabled again automatically.
58 If you use KDE, you can have it enabled in Control Center > Peripherals >
61 Also you can use NumlockX which can be found at
62 http://freshmeat.net/projects/numlockx/.
64 Or you can compile a simple C program yourself as described in the SuSE Support
65 Database (http://sdb.suse.de/en/sdb/html/cg_x11numlock.html), which is to be
68 Type the following to create the C source file:
70 cat > xsetnumlock.c << "EOF"
71 #include <X11/extensions/XTest.h>
72 #include <X11/keysym.h>
76 Display* disp = XOpenDisplay(NULL);
78 if (disp == NULL) return 1;
80 XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), True,
82 XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), False,
90 Now, compile it by typing:
92 gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o xsetnumlock xsetnumlock.c \
95 This will create a binary xsetnumlock which should be moved to /usr/bin or
96 /usr/X11R6/bin, whatever you want.
98 If gcc complains that it can't find XTest.h and/or keysym.h, do the following:
99 1. Unpack the X420src-1.tgz file (if you don't have it already, download it at
100 ftp://ftp.xfree86.org/pub/XFree86/4.2.0/source/). After unpacking, you'll
101 have a directory called xc.
102 2. Copy the file xc/include/extensions/XTest.h to
103 /usr/X11R6/include/X11/extensions and/or the file xc/include/keysym.h to
104 /usr/X11R6/include/X11.
106 And finally, add xsetnumlock to your .xinitrc (which can be found in your home
109 For example, my .xinitrc file looks something like this:
111 /usr/X11R6/bin/xsetnumlock
114 Congratulations, you're done! From now on, you will always be accompanied by
115 your loyal NumLock friend. Enjoy your NumPad.
119 I am thankful to Manfred Winter and Tushar Teredesai for their comments on this
124 Comments, improvements whatsoever on this hint will be received with
125 a warm welcome at the e-mail address mentioned in the AUTHOR field above.