H
H
hsuper2018-03-24 20:47:31
C++ / C#
hsuper, 2018-03-24 20:47:31

What does this line mean?

What does this line mean? => if(GetAsyncKeyState(VK_F1) & 1)
Why is there & 1 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2018-03-24
@hsuper

If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState.

Check for the least significant bit (short for if ((GetAsyncKeyState(VK_F1) & 1) != 0). It means: the key has been pressed at least once since the previous call to GetAsyncKeyState. On the one hand, this bit is not recommended (it works when there are no other programs calling GetAsyncKeyState). On the other hand, the least significant bit of GetAsyncKeyState () in the modern implementation of Windows works exactly as it should (if the program is inactive, GAKS returns 0.)
GAKS is commonly used in games and other dynamic programs; in production software, window messages are used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question