Page 1 of 1

GetAsyncKeyState, VK_LButton & Windows 95/98

Posted: Fri Mar 25, 2005 4:39 am
by Xombie
Hi,

I was reading up on using GetAsyncKeyState_() with #VK_LBUTTON but MSDN seems to say that Windows 95/98/ME would not work with that constant?

http://msdn.microsoft.com/library/defau ... ystate.asp
Windows 95/98/Me: The return value is the global asynchronous key state for each virtual key. The system does not check which thread has the keyboard focus.
Is it talking about distinguishing between the left & right shift keys or any constant with L/R in it?

I need to use GetAsyncKeyState_() with #BK_LBUTTON to determine if the left/right mouse button is depressed while in Callback and I can't use the normal wparam or lparam state checking because the #WM_MOUSEMOVE is within a #WM_SETCURSOR. I can detect when the user clicks the left or right mouse button just fine but if they hold it down and move only the #WM_MOUSEMOVE event is returned and I can't check lparam or wparam to see if the button is still down. Currently I'm using a global variable that is set/removed when a #WM_LBUTTONDOWN/UP even occurs but if the user hold the mouse button down, moves off of the window, lets go of the button (button up) and then return to the window, the program still thinks the button is down. That's why I need GetAsyncKeyState_() so I can proactively check the status of the left or right mouse button.

Soooooo.... :D Now that I've gone off on a tangent and given probably too much info.... is it true? #VK_LBUTTON or #VK_RBUTTON will always fail on Windows 95/98/ME?

Re: GetAsyncKeyState, VK_LButton & Windows 95/98

Posted: Fri Mar 25, 2005 5:03 am
by PB
> #VK_LBUTTON or #VK_RBUTTON will always fail on Windows 95/98/ME?

No, these constants work on 95/98/ME -- I've been using them for years! :)

Posted: Fri Mar 25, 2005 5:11 am
by Xombie
That would be awesome news :D

But I wonder what Microsoft was talking about? Were they just talking about keys and not mouse buttons?

Posted: Fri Mar 25, 2005 5:50 am
by PB
> I wonder what Microsoft was talking about?

If you mean the bit you quoted above, Microsoft are saying that the return
value is obtained no matter which app has the focus at the time of the call.
So you can use this API in your app even if another app is in use, and still
be able to see if the key/mouse has been pressed.

Posted: Fri Mar 25, 2005 6:04 am
by Xombie
Argh! >_< I quoted the wrong one. I meant this one:
Windows 95/98/Me: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero.

Posted: Fri Mar 25, 2005 6:36 am
by PB
Ah, okay: the MSDN article is referring to these specific key constants only:

VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL, VK_LMENU, VK_RMENU

Under Win 95/98/ME, these keys will return 0. On NT/2K/XP, they return
the state of the keys. So on 95/98/ME you have to check only the normal
key, specifically: VK_SHIFT, VK_CONTROL, VK_MENU. The mouse versions
(VK_LBUTTON, VK_MBUTTON, VK_RBUTTON) work on all Windows versions.

Also, in case it isn't obvious, VK_MENU is referring to the ALT key. ;)

Posted: Fri Mar 25, 2005 6:47 am
by Xombie
This is so great. I was tearing my hair out today trying to find an alternate method to detect the l/r mouse button status.

Thanks a lot for the info, PB! :D