On 04/08/13 10:35, Howard Rubin wrote:
> On Fri, 05 Apr 2013 23:39:28 -0700, Greg Ercolano wrote:
>> an fltk timer would probably be needed to get the correct
>> state info shown reliably.
>
> Thanks for the replies.
>
> No luck with an fltk timer, on Ubuntu Linux 10.04. Test program below.
>
> In the console we can see that (Fl::event_state() & FL_CAPS_LOCK)
> correctly changes to nonzero as soon as you press Caps Lock.
>
> But it doesn't change back to 0 when you press Caps Lock again
> until e.g. you move the mouse over the window.
I'm not sure if this is a bug in X11 or not.. kinda seems so.
X11's own "KeyRelease" events seem to behave similarly;
in my tests with the pure X11 code below, when X11 sends
a KeyRelease event for the capslock key, the "event.xkey.state"
shows accurate info when capslock is ENABLED, but INACCURATE INFO
when capslock is disabled.
You have to hit some other key to get the accurate state of
capslock after lock release.
So I think FLTK is simply passing this X11 behavior on to the app.
Not really sure if FLTK can fix this if X11 gives similar info.
My X11's a bit rusty, but there might be a way to acquire the realtime
capslock state by a different X library call -- if there is, you should
probably #ifdef that into your code.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
//
// Slightly modified X windows hello world
//
// ref: http://www.cuillin.demon.co.uk/nazz/trivia/hw/hw_c.html
// compile: g++ hello.c -o hello -lXtst -lX11 -lXext
//
int main(int argc, char *argv[])
{
Display *dpy; /* X server connection */
Window win; /* Window ID */
GC gc; /* GC to draw with */
XFontStruct *fontstruct; /* Font descriptor */
XGCValues gcv; /* Struct for creating GC */
XEvent event; /* Event received */
XSetWindowAttributes xswa; /* Temporary Set Window Attribute struct */
// OPEN DISPLAY
if ((dpy = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", argv[0], XDisplayName(NULL));
exit(1);
}
// CREATE 500x500 WINDOW
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
50,50,500,500, // x,y,w,h
0, // border width
0,0); // border color, bg color
XSelectInput(dpy, win, ExposureMask|KeyPressMask|KeyReleaseMask);
// MAP WINDOW
XMapWindow(dpy, win);
// EVENT LOOP
while (1) {
XNextEvent(dpy, &event);
switch ( event.type ) {
case Expose:
fprintf(stderr, "* Expose event\n");
if ( event.xexpose.count == 0) {
while (XCheckTypedEvent(dpy, Expose, &event));
// GET CURRENT WINDOW SIZE (FOR TEXT CENTERING)
XWindowAttributes xwa;
if (XGetWindowAttributes(dpy, win, &xwa) == 0)
break;
XClearWindow(dpy, win);
}
break;
case KeyPress:
case KeyRelease: {
const char *ename = (event.type==KeyPress) ? " Press" :
"Release";
printf("%s keycode=0X%04x, state=0X%04x\n", ename,
event.xkey.keycode, event.xkey.state);
break;
}
default:
fprintf(stderr, "* Ignored event '%d'\n", (int)event.type);
break;
}
}
return(1);
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk