On 28.03.2011 12:40, Ben Stott wrote:
As noted in #2527, the keyboard demo fails to pick up the right shift
key, instead claiming it to be a left shift.
This is because lParam&(1<<24) is 0 for the shift key, and only the
shift key, though I've no idea why this is the case (it *is* noted in
the keyboard demo as a known bug of Windows - at least, on 2.0).
IMHO it's not worth the effort, because it will fail anyway in some or
more cases - unless MS decide to do it The Right Way. To your questions:
I'd close the STR w/o resolution.
SVN r8535 has a fix for 2.0 on this. It just uses a boolean flag and
GetKeyState to determine whether or not rshift has been
pressed/released. I've tested this relatively thoroughly and it looks
like it holds up. If you want, I can see if I can bash together a 1.3
patch, or you can knock up your own...?
I've tested your version with FLTK 2.0 now, and it looks as if there are
problems if you press (and hold) both shift keys simultaneously and/or
with the resulting auto-repeat keypresses when you hold'em down for a
longer time.
I hacked a POC how to make it better, but this still doesn't fix *ALL*
keypress combinations I tested, although it seems to work better than
your version. Points taken into account:
- check key state only when Windows says it's VK_SHIFT
- save the last keydown key (left/right)
- check all toggle states by comparing saved and current state
This could probably be done better, and I wouldn't call GetKeyState()
for the same key more than once in the final version, but anyway, here
it is. Enjoy.
Albrecht
Index: src/win32/run.cxx
===================================================================
--- src/win32/run.cxx (Revision 8548)
+++ src/win32/run.cxx (Arbeitskopie)
@@ -1436,13 +1436,28 @@
for (i = 0; i < 256; i++) if (!extendedlut[i]) extendedlut[i] = vklut[i];
}
static bool rShiftWasOn = false;
- if (HIWORD(GetKeyState(VK_RSHIFT)) && !rShiftWasOn) {
- rShiftWasOn = true;
- lParam |= 1 << 24;
- } else if (rShiftWasOn) {
- rShiftWasOn = false;
- lParam |= 1 << 24;
- }
+ static bool lShiftWasOn = false;
+ static char LastShiftOn = 0; // 0 | 'L' | 'R'
+ if (vk == VK_SHIFT) {
+ if (HIWORD(GetKeyState(VK_RSHIFT)) && !rShiftWasOn) {
+ rShiftWasOn = true;
+ LastShiftOn = 'R';
+ lParam |= 1 << 24;
+ } else if (!HIWORD(GetKeyState(VK_RSHIFT)) && rShiftWasOn) {
+ rShiftWasOn = false;
+ LastShiftOn = 0;
+ lParam |= 1 << 24;
+ } else if (HIWORD(GetKeyState(VK_LSHIFT)) && !lShiftWasOn) {
+ lShiftWasOn = true;
+ LastShiftOn = 'L';
+ } else if (!HIWORD(GetKeyState(VK_LSHIFT)) && lShiftWasOn) {
+ lShiftWasOn = false;
+ LastShiftOn = 0;
+ } else { // repeat
+ if (LastShiftOn == 'R')
+ lParam |= 1 << 24;
+ }
+ } // VK_SHIFT
if (lParam&(1<<24)) {
if (!(lParam&(1<<31))) fl_last_was_extended = true;
return extendedlut[vk];
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev