[try Beta version]
Not logged in

 
Explanation of function

Jan 31, 2013 at 11:08pm
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 Jan 31, 2013 at 11:08pm
Jan 31, 2013 at 11:17pm
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 Jan 31, 2013 at 11:18pm
Jan 31, 2013 at 11:26pm
i gathered that much but what is it doing with that memory address there?
Jan 31, 2013 at 11:45pm
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.
Jan 31, 2013 at 11:53pm
thanks cire! I barely understand that but at least something :D
Last edited on Jan 31, 2013 at 11:53pm
Feb 1, 2013 at 12:08am
I think cire explained it as best it could be explained.
Feb 1, 2013 at 12:11am
I never said he did not
Topic archived. No new replies allowed.