> I looked into it, and it looked okay so far, but I'm wondering whether
> you could check the key state only when you know it's a SHIFT key anyway.
> This might filter lots of GetKeyState() calls for unrelated key events.
> I started investigating whether someone in the 'net would tell how
> "expensive" GetKeyState was, but then something interrupted my research, and
> I still don't know. Maybe you found something about it? IIRC there are more
> calls to GetKeyState() in the code anyway, so it is maybe not very expensive.
>
Yes, I've seen notes in the code regarding the fact that GetKeyState
might be expensive, but I've found nothing to prove (or disprove) this,
for that matter. Purely through speculation, I'd hope GetKeyState would
be a function that does a simple constant-time lookup of an array -
given that the GetKeyboardState function returns an array (and based on
my interpretation of the documentation, is *not* asynchronous) of the
current keyboard state, I would hope that GetKeyState's implementation
is relatively smart. However, being a Microsoft API, this is definitely
not guaranteed.
It did just occur to me, however, that the key passed to ms2fltk will be
VK_RSHIFT, and through the use of that boolean state flag that we have,
we can simply test if (vk == VK_RSHIFT && !rShiftWasOn) { ... } else if
(... ) { ... }. That should do the same job, as this new check
determines whether or not the key is up/down by itself. Hmm, I might
test and re-commit this if this is the case.
> One more for my curiosity: Earlier in this thread you wrote:
> "GetKeyState() ... seemed to be static in my tests - hitting right shift and
> then any left modifing key would see the keyboard demo report a right key
> until
> right shift was hit *again*,..."
>
> Now it seems to work as expected. What changed?
I read the documentation :-P
It turns out that GetKeyState() stores a 'toggle' state in the first bit
and the up/down state in the last bit (of an unsigned short), so testing
if (GetKeyState(VK_RSHIFT)) will always return true after you press the
rshift key (as it's toggled to 'on'). I corrected this by using the
HIWORD macro, which takes the top bits instead of all of them. This was
documented, though it's somewhat pushed to the side a bit and terribly
illogical for a shift button to have a toggle setting. In any case,
HIWORD was the solution.
Regards,
Ben
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev