Jump to content

  • Log In with Google      Sign In   
  • Create Account


GetAsyncKeyState() Alt key problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 03 June 2014 - 09:05 PM

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, 03 June 2014 - 09:06 PM.


Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3389

Like
0Likes
Like

Posted 03 June 2014 - 10:56 PM

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, 03 June 2014 - 10:57 PM.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#3 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 03 June 2014 - 11:38 PM

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, 03 June 2014 - 11:43 PM.


#4 Icebone1000   Members   -  Reputation: 1017

Like
1Likes
Like

Posted 04 June 2014 - 12:47 AM

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.



#5 imoogiBG   Members   -  Reputation: 1056

Like
0Likes
Like

Posted 04 June 2014 - 03:45 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS