Skip to main content
GameDev.net gamedev.net
🔒 Locked

GetAsyncKeyState

Started by adam17 Aug 10, 2005 at 2:15 AM 2 replies 700+ views
Original Post
adam17
adam17
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?
Colin Jeanne
Colin Jeanne
// Use this to see if a VK_* is pressedbool 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.
Ximmer
Ximmer
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)
adam17
adam17
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.