Just a correction.
GetAsyncKeyState returns various key states based on bits set.
You can determine if a key is being held down ( for a while ) by checking the highest bit and you can determine if it has been pressed once ( KeyUp + KeyDown ) by checking the lowest bit.
Esentially:
P.S. NEVER just check if( GetAsyncKeyState() ) as the value returned could evaluate to true even though the key wasn't pressed. ( Check MSDN ) The above is guaranteed to work
- - - Updated - - -
Just a correction.
GetAsyncKeyState returns various key states based on bits set.
You can determine if a key is being held down ( for a while ) by checking the highest bit and you can determine if it has been pressed once ( KeyUp + KeyDown ) by checking the lowest bit.
Esentially:
P.S. NEVER just check if( GetAsyncKeyState() ) as the value returned could evaluate to true even though the key wasn't pressed. ( Check MSDN ) The above is guaranteed to work
GetAsyncKeyState returns various key states based on bits set.
You can determine if a key is being held down ( for a while ) by checking the highest bit and you can determine if it has been pressed once ( KeyUp + KeyDown ) by checking the lowest bit.
Esentially:
Code:
bool KeyDown( int key, bool checkHeldDown = false ){
return ( bool )GetAsyncKeyState( key ) >> ( checkHeldDown ? 31 : 0 );
}
- - - Updated - - -
Just a correction.
GetAsyncKeyState returns various key states based on bits set.
You can determine if a key is being held down ( for a while ) by checking the highest bit and you can determine if it has been pressed once ( KeyUp + KeyDown ) by checking the lowest bit.
Esentially:
Code:
bool KeyDown( int key, bool checkHeldDown = false ){
return ( bool )GetAsyncKeyState( key ) >> ( checkHeldDown ? 31 : 0 );
}

