Regarding: XQueryKeymap reports incorrect state of NUM LOCK
Email: [EMAIL PROTECTED]
------------------------------------------------------------
XFree86 Version: XFree86 Version 4.2.0 (Red Hat Linux release: 4.2.0-72)
OS: Red Hat Linux 8.0 - OS Kernel: Linux version 2.4.18-24.8.0
Area: XServer
Server: XFree86 (The XFree86 4.x server)
Video Card:
N/A
Description:
I see a problem with the use of XQueryKeymap when run against a
Linux Xserver to determine if NumLock is on or off.
Using XQueryKeymap it only reports NumLock as on when the key is
physically held down.
If I run against, for example Solaris's Xserver, if the NumLock LED
is on, then I will see that using XQueryKeymap.
I've pasted a simple test progam in the "Repeat by" section below.
Repeat By:
#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");
}
Against 4.2 (but also a 4.1 server) I see:
$ ./led
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00
False
# Now I turn on NUMLOCK on the keyboard.
$ ./led
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00
False
When I set my display to be a Solaris 8 Xserver:
$ ./led
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00
False
# Turn on NUMLOCK
$ ./led
00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00
True
_______________________________________________
XFree86 mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/xfree86