Jump to content
  • Advertisement
Sign in to follow this  
adam17

GetAsyncKeyState

This topic is 4844 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

im still trying to implement a console into my program but at this point im having an issue with opening and closing it. at the moment im using GetAsyncKeyState to tell whether or not the "console key" is being pressed. unfortunately GetAsyncKeyState returns a short value, not a boolean. is there a function or something i can do to the return value to make it boolean. i need something simple like "Key is Up" or "Key is Down." any suggestions?

Share this post


Link to post
Share on other sites
Advertisement

// Use this to see if a VK_* is pressed
bool IsKeyDown(int vKey) {
return GetAsyncKeyState(vKey) & 0x8000;
}



You just need to test the most significant bit to see if the key is up or down.

Share this post


Link to post
Share on other sites
I do beleive this code should work


bool GetKeyState(int VKey)
{
if(GetAsyncKeyState(VKey) & 0x8000) return true;

return false;
}



if not then replace 0x8000 with 0x0001

GetAsyncKeyState serves 2 functions. "Get whether the key is up or down" and "Was the key pressed since the last call to GetAsyncKeyState)

Share this post


Link to post
Share on other sites
hell yeah! thanks.

i need to learn more about most significant bits and least significant bits. it seems like everyday i feel i know everything about c++ and everyday i learn something new.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!