C++ 用GetAsyncKeyState() 获取所有按键码

简介: C++ 用GetAsyncKeyState() 获取所有按键码

无聊地把整张虚拟键码表放进一个数组^_^

#include <iostream>
#include <iomanip>
#include <windows.h>
#include <array>
using namespace std;
void gotoXY(short x, short y)
{
    COORD position = {x, y};
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hConsole, position);
}
array<string,256> VKCode={
"",
/*001-*/"LBUTTON","RBUTTON","CANCEL","MBUTTON","XBUTTON1","XBUTTON2","","BACK","TAB","",
/*011-*/"","CLEAR","RETURN","","","SHIFT","CONTROL","MENU","PAUSE","CAPITAL",
/*021-*/"","","","","","","ESCAPE","","","",
/*031-*/"","SPACE","PRIOR","NEXT","END","HOME","LEFT","UP","RIGHT","DOWN",
/*041-*/"SELECT","PRINT","EXECUTE","SNAPSHOT","INSERT","DELETE","HELP","0","1","2",
/*051-*/"3","4","5","6","7","8","9","","","",
/*061-*/"","","","","A","B","C","D","E","F",
/*071-*/"G","H","I","J","K","L","M","N","O","P",
/*081-*/"Q","R","S","T","U","V","W","X","Y","Z",
/*091-*/"LWIN","RWIN","APPS","","SLEEP",
/*096-*/"NUMPAD0","NUMPAD1","NUMPAD2","NUMPAD3","NUMPAD4",
/*101-*/"NUMPAD5","NUMPAD6","NUMPAD7","NUMPAD8","NUMPAD9",
/*106-*/"MULTIPLY","ADD","SEPARATOR","SUBTRACT","DECIMAL",
/*111-*/"DIVIDE","F1","F2","F3","F4","F5","F6","F7","F8","F9",
/*121-*/"F10","F11","F12","F13","F14","F15","F16","F17","F18","F19",
/*131-*/"F20","F21","F22","F23","F24","","","","","",
/*141-*/"","","","NUMLOCK","SCROLL","","","","","",
/*151-*/"","","","","","","","","","LSHIFT",
/*161-*/"RSHIFT","LCONTROL","RCONTROL","LMENU","RMENU",
/*166-*/"BROWSER_BACK","BROWSER_FORWARD","BROWSER_REFRESH","BROWSER_STOP","BROWSER_SEARCH",
/*171-*/"BROWSER_FAVORITES","BROWSER_HOME","VOLUME_MUTE","VOLUME_DOWN","VOLUME_UP",
/*176-*/"MEDIA_NEXT_TRACK","MEDIA_PREV_TRACK","MEDIA_STOP","MEDIA_PLAY_PAUSE","LAUNCH_MAIL",
/*181-*/"LAUNCH_MEDIA_SELECT","LAUNCH_APP1","LAUNCH_APP2","","",
/*186-*/"OEM_1","OEM_PLUS","OEM_COMMA","OEM_MINUS","OEM_PERIOD",
/*191-*/"OEM_2","OEM_3","","","","","","","","",
/*201-*/"","","","","","","","","","",
/*211-*/"","","","","","","","","OEM_4","OEM_5",
/*221-*/"OEM_6","OEM_7","OEM_8",
/*
186【;:】VK_OEM_1
187【=+】VK_OEM_PLUS
188【,<】VK_OEM_COMMA
189【-_】VK_OEM_MINUS
190【.>】VK_OEM_PERIOD
191【/?】VK_OEM_2
192【`~】VK_OEM_3
219【[{】VK_OEM_4
220【\|】VK_OEM_5
221【]}】VK_OEM_6
222【'"】VK_OEM_7
空值为未定义值或非标准键盘的Key 
*/
};
int main()
{
  gotoXY(15,8);
  cout<<"请按键:"; 
  while(1){
    for (int i=1;i<=255;i++){
        if (GetAsyncKeyState(i)&1){
          gotoXY(24,8);
            cout<<"\t\t\t\t\b\b\b\b"<<dec<<i<<"(10)"<<hex<<i<<"(16):VK_"<<VKCode.at(i);
        }
    }
  }
  return 0; 
}
目录
相关文章
|
7月前
|
数据安全/隐私保护 Windows
Proxmox创建Windows虚拟机
Proxmox创建Windows虚拟机
204 0
|
3月前
|
PHP 开发者
slowlog 和 request_slowlog_timeout
slowlog 和 request_slowlog_timeout
104 3
|
7月前
|
数据处理
正则表达式详解:解析星号的含义
【4月更文挑战第3天】
889 1
正则表达式详解:解析星号的含义
|
6月前
|
NoSQL 程序员 C语言
探秘Segmentation Fault错误:程序猿的噩梦
探秘Segmentation Fault错误:程序猿的噩梦
|
机器学习/深度学习 Windows
easyx库的介绍与使用(二)
easyx库的介绍与使用(二)
|
缓存 安全 Unix
C/C++使用Windows的API实现共享内存以及同步
C/C++使用Windows的API实现共享内存以及同步
1563 0
|
传感器 编解码 测试技术
CVPR'2023 | Nerf-Stereo: 利用NeRF来训练双目立体匹配网络的新范式!
CVPR'2023 | Nerf-Stereo: 利用NeRF来训练双目立体匹配网络的新范式!
597 0
|
机器学习/深度学习 传感器 存储
Pillar-Base | 超越SECOND、PointPillar等一系列3D目标检测,PillarNet=Pillar王者
Pillar-Base | 超越SECOND、PointPillar等一系列3D目标检测,PillarNet=Pillar王者
940 0
Pillar-Base | 超越SECOND、PointPillar等一系列3D目标检测,PillarNet=Pillar王者
|
数据可视化 编译器 C++
C++ 用DEV-C++建一个Windows窗口程序带文本框和命令按钮
C++ 用DEV-C++建一个Windows窗口程序带文本框和命令按钮
2276 0