dob990
dob990

Reputation: 21

C/C++ GetAsyncKeyState() Key combination

I understand how to use this function with one key, but how can I use it with two keypresses?

Like: GetAsyncKeyStat(VK_LBUTTON && VK_RBUTTON);

Upvotes: 1

Views: 9113

Answers (2)

Igor Zevaka
Igor Zevaka

Reputation: 76500

You would have to call GetAsyncKeyState twice.

//"And" the returns of GetAsyncKeyState
//Then "and" the result with 0x8000 to get whether or not the Most Significant Bit is set
bool bBothPressed = GetAsyncKeyState(VK_LBUTTON) & GetAsyncKeyState(VK_RBUTTON) & 0x8000;

Upvotes: 6

Elemental
Elemental

Reputation: 7466

Generally the best answer if you want to query multiple keys is to use GetKeyboardState that returns the state of every Virtual key in an array which you can process directly and efficiently.

Upvotes: 3

Related Questions