Re: GetAsyncKeyState(VK_LBUTTON) true after DoModal()
"Simon" <bad@example.com> wrote in message
news:Ok9B0Jh1KHA.5996@TK2MSFTNGP05.phx.gbl...
if ( GetAsyncKeyState(VK_LBUTTON & 0x8000) ) // don't compare == 0x8000
;
I am curious, why do you suggest that? I agree that both essentially mean
the same thing, but why do you suggest not comparing to 0x8000?
Also are you sure it is
if ( GetAsyncKeyState(VK_LBUTTON & 0x8000) )
and not
if ( GetAsyncKeyState(VK_LBUTTON) & 0x8000 )
?
Yes, you are right, it should be the latter one:
if ( GetAsyncKeyState(VK_LBUTTON) & 0x8000 )
Essentially GetAsyncKeyState() returns a bitfield, you are masking the most
significant bit, and you need to test whether that is non-zero. That intent
is most clearly expressed by not doing == 0x8000, which implies comparison
to an integer (not a bitfield) and does not imply testing for bits set.
If this still does not work, what if you close the dialog by setting
focus to the OK button and use the keyboard? Does it then work? There
might be something going on with the dialog's DoModal() as that is a
separate message loop running, which might screw up the cached keyboard
state (although I understand GetAsyncKeyState doesn't use a cached
state, it is supposed to be what the hardware state is at the moment you
call it.)
When I select the Ok button with the keyboard then the left button does
not report as been down.
I don't exactly know what's going on, but try using GetKeyState() instead of
GetAsyncKeyState(). I'm not sure if this works with VK_LBUTTON, so also try
GetKeyboardState(). These functions sync the results with the message loop.
-- David