使用GetAsyncKeyState
不能检测到'~'
按钮(位于键盘的左上方)。
那么有什么方法可以检测到此按钮吗?
还是应该使用其他命令?
通过我使用c ++的方式
答案 0 :(得分:0)
虚拟键代码“〜”为VK_OEM_3
。
可以参考更多虚拟按键代码:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
如何使用它,请参阅MSDN
一个简单的例子:
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
BOOL OEM_3 = FALSE;
while (1)
{
if (GetAsyncKeyState(VK_OEM_3) < 0 && OEM_3 == false)
{
//Press down
OEM_3 = true;
cout << "Press down" << endl;
}
if (GetAsyncKeyState(VK_OEM_3) >= 0 && OEM_3 == true)
{
//Release
OEM_3 = false;
cout << "Release" << endl;
}
}
return 0;
}