To enable NumLock in the console, paste this code into rc.local or make an init script and put it into /etc/init.d/:
echo "Enabling NumLock..."
for tty in /dev/tty{1,2,3,4,5,6,7,8,9,10,11,12}; do
setleds -D +num < $tty
done
X windows is nice enough to turn this off again... so paste the following code into a file named xsetnumlock.c:
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
int main(void)
{
Display* disp = XOpenDisplay(NULL);
if (disp == NULL) return 1;
XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), True, CurrentTime);
XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), False, CurrentTime);
XCloseDisplay(disp);
return 0;
}
Run this command to compile it:
$ gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o xsetnumlock xsetnumlock.c -lX11 -lXtst
Run xsetnumlock from ~/.Xclients (or any of its alternatives: .xsession, .xinitrc or whatever...).
|