Archived

This topic is now archived and is closed to further replies.

J_T_Biggs

GetAsyncKeyState win98 Problem

Recommended Posts

I was using the function GetAsyncKeyState to get the keys: VK_UP VK_DOWN VK_RETURN VK_ESCAPE now all of them work fine except for the VK_RETURN. I created a function to take the nonzero number (key is pressed) and zero (key is up) to generate true/false so i could easily tell if the key i want is up or down. The function works with all the keys except return. I created a test program to see what was wrong and the return key seemed to produce opposite results from the other keys. The function below converts the return ot GetAsyncKeyState to true/false.
    bool KeyState(int KeyType)
{
	if (GetAsyncKeyState(KeyType) != 0)
	{
		return (true);
	} else {
		return (false);
	}
}    
i went to msdn to see what they had to say about the GetAsyncKeyState function. Now i have a windows 98 computer and they said that the function returns: 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. it also says something about "most and least significant byte returned by the function" what does that mean and how do i successfully use the function so i can get the key inputs correctly. i got my information here. check this out to see what i mean: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/keybinpt_1x0l.asp ------------------------- J_T_Biggs - 2001 Edited by - J_T_Biggs on July 29, 2001 11:38:49 AM

Share this post


Link to post
Share on other sites
The most significant byte of a DWORD is this one :
10000000 00000000 00000000 00000000
^

written in hex, the value is 0x8000

so, you have to check if the bits of the value 0x8000 are set in the return value of GetAsyncKeyState.
In C, it''s done with &

So, you do "if( GetAsyncKeyState( KeyType ) & 0x8000 )"

Have fun

Share this post


Link to post
Share on other sites
Actually, the most significant bit of a DWORD is 0x80000000, but you''re right, you want to check for 0x8000.

If the MSB is set, that means the key is down *now*, otherwise, all the call tells you is if the key has been pressed sometime since the last call, which doesn''t cut it most of the time.

Good luck.

Share this post


Link to post
Share on other sites
Uhm! I dont know how to do that with C/C++, but in Delphi I would do that like this...

If (GetAsyncKeyState(KeyType) and $8000) <> 0 Then
Key is down..
else
key is up....


In C/C++ it would go somehow like this....

If (GetAsyncKeyState(KeyType) & 0x8000) != 0)
{
key is down....
}
else
{
key is up...
}



Edited by - Spoogy on July 30, 2001 3:48:59 AM

Share this post


Link to post
Share on other sites