• Advertisement
Sign in to follow this  

GetAsyncKeyState() Alt key problem

This topic is 1328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

I have a funny issue when using GetAsyncKeyState() in my application.

I am using the following code to switch between full screen and windowed mode.
 
if(GetAsyncKeyState(VK_ENTER) && GetAsyncKeyState(VK_MENU))
{
    // react on Alt & Enter keypress
}
But, the Alt key acts as though it is being held.

Pressing Alt & Enter similtaneously works fine.

But, pressing Alt (wait for 10 seconds) then Enter also triggers the event. (Not good)

But, pressing Enter (waiting) then Alt doesn't trigger the event (This is good).

It is like when you press Alt to get a menu and then enter to select the item. Although I am not using any menu's and have no menu's tied to the window in my application.

Any ideas how I can stop this behavior?

Thanks in advance smile.png Edited by lonewolff

Share this post


Link to post
Share on other sites
Advertisement

You better use WM_SYSKEYDOWN to check for Alt-Enter. This behaves properly as it marks the key press as handled (return zero).

 

Using GetAsyncKeyState just returns the current state but does not do any changes to the system keyboard states.

Edited by Endurion

Share this post


Link to post
Share on other sites
Actually I forgot to mention that I have this in the Callback
 
case WM_SYSCOMMAND:
{
	if(wParam==SC_KEYMENU && (lParam>>16)<=0)
		return 0;
}
break;
The above code stops the 'Restore,Move,Size,etc..' box from popping up but doesn't stop the behavior as mentioned.

[edit]
I just changed the key polling to...

if(GetAsyncKeyState(VK_MENU)&0x8000)&&(GetAsyncKeyState(VK_ENTER)&0x8000))

and it worked smile.png

I have no idea what the 0x8000 does though. Edited by lonewolff

Share this post


Link to post
Share on other sites

8 in binary is 1000, means it have the left most bit set, getasynk.. returns a bitmask where each bit means something, check the docs in msdn.

If the left bit is set, the key is down.

Share this post


Link to post
Share on other sites

GetAsyncKeyState(KEY) & 0x8000 or GetAsyncKeyState(KEY) & 0x80 (just can remember) 

This will be true if the key is down. Alt + Enter is a system command as said above better use the message proc

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement