检查是否按下了 ALT 键

标签 c windows keyboard-shortcuts

经过大量测试后,我无法在 C 程序中使用 GetAsyncKeyState 记录是否按下 Alt 键。 当我尝试这个时:

if (GetAsyncKeyState(VK_SHIFT))
    // do something

它工作正常,但是当我尝试这个

if (GetAsyncKeyState(VK_MENU))
    // do something

这不起作用。
所以我的问题是“我如何记录 ALT?”。

提前致谢

最佳答案

我使用下面的代码来找出完全适合 GetAsyncKeyState 的任何键的值,我认为 ALT key 的值是 18。

#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 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43724247/

相关文章:

visual-studio-code - 如何使用键盘在 Visual Studio Code 中移动选项卡?

c - 链表段错误a

我可以假设 long int 的大小总是 4 个字节吗?

c++ - fatal error : google/protobuf/port_def. inc : No such file or directory #include <google/protobuf/port_def. inc>

windows - 有没有办法为 "DIR"命令转义空格

c# - 在 Visual Studio 2013 中填充构造函数变量的快捷方式是什么?

c - 如果有堆栈溢出,linux 会告诉我吗?

c - 什么时候指向内存区域最后一个元素的指针对指针运算有效?

c# - 如何使用windows应用程序在第三方网站上填写并提交网页表单?

c# - 在 Visual Studio 的界面中为所有定义的方法生成方法 stub 的快捷方式是什么?