How to get Numlock on by default in X ?

Joe Morris heartboy at
Sun Nov 24 15:45:00 PST 2002

On Sunday 24 November 2002 04:59 pm, you wrote:
> This may be an RTFM but I've grepped the man pages on my blfs system
> for numlock and only find references on using numlock as a key
> modifier.  Same thing in the documentation I downloaded from
>  I also recompiled the numlockx utility I have been using
> on my host system (under 3.3.6) but it doesn't work under 4.2.1.
> I had thought that 4.2.1 might have it's own option for setting the
> numlock on when X starts, but I don't find one in the
> file.
> So where do I look ?
> Thanks,
> Wayne

Here is what I do.  Pop the following in a .c file:

#include <X11/extensions/XTest.h>
#include <X11//keysym.h>

int main(){
        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);
        return 0;

Then compile with: 
gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o setnumlock setnumlock.c -lX11 

Then execute the command in your ~/.xinitrc.  Works for me.
Unsubscribe: send email to listar at
and put 'unsubscribe blfs-support' in the subject header of the message

More information about the blfs-support mailing list