#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#include <sys/types.h>

#include <stdio.h>

int main( int argc, char *argv[] )
{
    KeySym      sym;
    KeyCode     keyCode;
    u_int32_t   byteIndex;
    u_int32_t   bitIndex;
    char        keyVector[32];
    Display    *display;
    int         i;

    if ( (display = XOpenDisplay(NULL) ) == NULL ) {
        fprintf(stderr,"Unable to open display\n");
        exit( 1 );
    }

    keyCode = XKeysymToKeycode(display, XK_Num_Lock);

    if (keyCode == 0) {
        fprintf(stderr,"Invalid KeyCode\n");
        return False;
    }
                                                                                
    byteIndex = (keyCode/8);
    bitIndex = keyCode & 7;
    XQueryKeymap(display, keyVector);

    fprintf(stderr,"\n");
    for ( i = 0; i < 32; i++ )
        fprintf(stderr,"%02X ", keyVector[i]);
    fprintf(stderr,"\n");
                                                                                
    if (1 & (keyVector[byteIndex] >> bitIndex)) 
        fprintf(stderr,"True\n");
    else
        fprintf(stderr,"False\n");
}
