GetAsyncKeyState function checks whether key is up or down , Sets the 15th bit of return value as signed short , Signed short extends to int in comparison if block, If key is down, 15th bit will be set thus result will be a negative :
Comparison also can be done GetAsyncKeyState(vKey) < 0
-
0x8000(Bit 15 - Most Significant Bit): Indicates whether the key is currently DOWN. -
0x0001(Bit 0): Indicates whether the key was pressed after the previous call. -
By performing a bitwise AND operation (
GetAsyncKeyState(VK_SPACE) & 0x8000),
we effectively isolate the MSB to determine the instant physical state of the key regardless of window focus.