检查是否按了ALT键 [英] Check if ALT key is pressed
本文介绍了检查是否按了ALT键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
经过大量测试,我无法记录是否在C程序中使用 GetAsyncKeyState 按下了Alt键. 当我尝试这个:
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
它不起作用.
所以我的问题是如何记录ALT?".
It doesn't work.
So my question is "How I can record ALT?".
预先感谢
推荐答案
我使用下面的代码找出完全适合GetAsyncKeyState
的任何键的值,我认为ALT
键为18. /p>
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;
}
这篇关于检查是否按了ALT键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文