On 11 Apr 2013, at 18:34, Greg Ercolano wrote:
> I guess we should see how Win32 and OSX behave, and if they're
> "reliable"
> as well, we should either:
>
> 1) Document the OS specific behavior, whether different or same,
> and leave the code alone
> 2) Pick one behavior, and modify the code to enforce it, and
> document it
Can. Of. Worms.
Attached below, my take on this. It's messy...
However, the code given returns the "correct" state on OSX 10.6.8,
Linux-in-a-VM, and WinXP.
What I find (at least on my systems...)
- On Linux, ONLY look at the FL_KEYDOWN events
- On WIN32, ONLY look at the FL_KEYUP events (and the sense is maybe inverted
wrt the linux case)
- On OSX, I need to process both up and down events, because it looks (and I
may be really losing the plot here) as if I only get keydown events when the
Caps Lock is going on, and I only get keyrelease events if the Caps Lock is
going off...
So... The code works, but it is not nice:
--------------
//
// FLTK CAPSLOCK TEST
// compile: fltk-config --compile test-capslock-fltk.cxx
//
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
static Fl_Box *state_box = 0;
static unsigned updn = 0;
static unsigned updn_old = 0;
static void change_state_box(void) {
if(updn != updn_old) {
updn_old = updn;
if(updn) {
state_box->color(FL_RED);
state_box->label("ON");
}
else {
state_box->color(FL_BLACK);
state_box->label("OFF");
}
state_box->redraw();
}
} // change_state_box
class MyWindow : public Fl_Window {
public:
MyWindow(int W,int H) : Fl_Window(W,H) { }
int handle(int e) {
switch (e) {
case FL_KEYUP:
#ifdef __APPLE__
if ((Fl::event_state() & FL_CAPS_LOCK) != 0) {
updn = 999;
}
else {
updn = 0;
}
change_state_box();
#endif // __APPLE__
#ifdef WIN32
if ((Fl::event_state() & FL_CAPS_LOCK) != 0) {
updn = 0;
}
else {
updn = 999;
}
change_state_box();
#endif // WIN32
break;
case FL_KEYDOWN:
#ifndef WIN32
if ((Fl::event_state() & FL_CAPS_LOCK) != 0) {
updn = 999;
}
else {
updn = 0;
}
change_state_box();
#endif // !WIN32
break;
default:
break;
}
return(Fl_Window::handle(e));
} // handle
};
static MyWindow *win = 0;
int main(int argc, char **argv) {
win = new MyWindow(500,500);
win->begin();
state_box = new Fl_Box(10, 10, 80, 40, "OFF");
state_box->color(FL_BLACK);
state_box->box(FL_FLAT_BOX);
state_box->labelcolor(FL_WHITE);
win->end();
win->show(argc, argv);
return Fl::run();
} // main
// end of file
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk