问题
After testing a lot I can't record if Alt key is pressed using GetAsyncKeyState in a C program. When I try this:
if (GetAsyncKeyState(VK_SHIFT))
// do something
It works properly, but when I try this
if (GetAsyncKeyState(VK_MENU))
// do something
It doesn't work.
So my question is "How I can record ALT?".
Thanks in advance
回答1:
I use the code below to find out the value of any key that perfectly fits in GetAsyncKeyState
, I think it is 18 for ALT
key .
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#if _WIN32_WINNT < 0x0500
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <windows.h>
using namespace std;
int main ()
{
char i;
for(i=8; i<190; i++)
{
if(GetAsyncKeyState(i)== -32767)
{
cout<<int (i)<<endl;
}
}
return 0;
}
来源:https://stackoverflow.com/questions/43724247/check-if-alt-key-is-pressed