windows C/C++ GetAsyncKeyState() 组合键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2800663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C/C++ GetAsyncKeyState() Key combination
提问by dob990
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);
像:GetAsyncKeyStat(VK_LBUTTON && VK_RBUTTON);
回答by Igor Zevaka
You would have to call GetAsyncKeyState
twice.
你将不得不打电话GetAsyncKeyState
两次。
//"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;
回答by Elemental
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.
通常,如果您想查询多个键,最好的答案是使用 GetKeyboardState 返回数组中每个虚拟键的状态,您可以直接有效地处理该状态。