Previously my app was keeping track of keys down by simply recording
keydowns and keyups.  The advantage of this over Fl::event_state() is
that I can treat any key as a modifier, map ControlL separately from
ControlR, and it's simpler to not have the separate Modifier type
(FL_SHIFT, etc.) and treat all keys equally (yes I know kbd drivers
tend to not be able to track every key like a modifier, but the OS X
kbd at least does pretty well).  However, I had a problem with stuck
keys, because holding a key and then unfocusing the app (say cmd-tab
on OS X) will give a keydown but no keyup.  So I decided that separate
ControlL and ControlR is not worth that much and checking
Fl::event_state() every time would be less error prone.
Unfortunately, there's still a bit of a problem: FL_FOCUS on OS X
apparently doesn't update Fl::event_state().  So from the focus until
the first keydown, event_state() is telling me that the modifier is
still held.

Another problem is that I used to use keeping track of all keydowns to
determine when a keydown is a repeat.  I can still do that by
continuing to keep a keydown map, and I *think* this is reliable when
used only for detecting repeats.  But isn't this something fltk could
tell more reliably than I could?

So I think the failure to update event_state() on FOCUS is probably
just a bug and would be easily enough fixed.  But the wider question
is, is there a way to accurately track kbd state for all keys?  Either
I would have to have some way of getting a guarantee that every
keydown gets a corresponding keyup (but to do this correctly might
require the OS to send an event when it's just not designed to do
that), or there could be some way of getting a bitmap of the entire
kbd state.  This would require fltk to do what I can't, namely keep
track of kbd state accurately, but maybe it would be in a better
position, since it could ask the OS for a refresh on all keys whenever
the app got focus.

Reliable handling of kbd state seems like a basic feature to me that
all apps would want to have, so what's the "right way" to do it?  I
think I'm unusual in that I want to handle my own modifiers at a low
level where many apps are satisfied with built-in ways to bind certain
mod+letter combos, but it's hardly a totally crazy things to want to
do.  Games, for instance, would want to track multiple key downs
accurately.

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to