Explanation of function

1
2
3
4
bool inline KEYDOWN(int vkCode) 
{
return (GetAsyncKeyState(vkCode) & 0x8000) ? true : false;
}


I know what it does, but I have no idea how it works, can someone explain it to me? I mean this part

(GetAsyncKeyState(vkCode) & 0x8000) ? true : false;
Last edited on
GetAsyncKeyState determines if a key is up or down.

(condition) ? (return type)

sort of like:
1
2
3
4
if (something) 
    return true
else 
    return false
Last edited on
i gathered that much but what is it doing with that memory address there?
There is no memory address there.

0x8000 is a value (in hexadecimal notation) that serves as a bitmask. In binary it would look like: 10000000000000000000000000000000 (which you can see has only the most signficant bit set.) Using the bitwise and operator on this value and the value returned by GetAsyncKeyState results in another value that is not equal to 0 if the value returned by GetAsyncKeyState had it's most significant bit set and is equal to 0 if the value returned by GetAsyncKeyState did not have it's most significant bit set.
thanks cire! I barely understand that but at least something :D
Last edited on
I think cire explained it as best it could be explained.
I never said he did not
Topic archived. No new replies allowed.