Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the high- and low-order bits of a SHORT?

Tags:

c++

winapi

short

The function GetKeyState() returns a SHORT that contains the key's state (up/down in the high-order bit, and toggled in the low-order). How do I get those values?

like image 451
Dylan Avatar asked Mar 14 '11 18:03

Dylan


1 Answers

That's not how you use the return value of GetKeyState(). Do it like this instead:

SHORT state = GetKeyState(VK_INSERT);
bool down = state < 0;
bool toggle = (state & 1) != 0;
like image 135
Hans Passant Avatar answered Oct 24 '22 21:10

Hans Passant