无论如何,我可以使用GetAsyncKeyState来检测"~"吗?

Is there anyway i can detect "~" by using GetAsyncKeyState?

本文关键字:检测 GetAsyncKeyState 我可以 可以使 无论如何      更新时间:2023-10-16

通过使用GetAsyncKeyState它无法检测到'~'按钮(在键盘的左上角(。
那么有什么方法可以检测这个按钮吗?
还是我应该使用另一个命令?

顺便说一下,我正在使用c ++

"~"的虚拟键码是VK_OEM_3

可以参考更多虚拟键代码:

https://learn.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;
}