可以使用下面的两个Win32函数

GetKeyState

The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).

SHORT GetKeyState(int nVirtKey   // virtual-key code
); nVirtKey   // virtual-key code
);

Parameters

nVirtKey

[in] Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9),nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.

If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the "o" key, whereas VK_OEM_1 refers to the "o with umlaut" key.

Return Values

The return value specifies the status of the specified virtual key, as follows:

  • If the high-order bit is 1, the key is down; otherwise, it is up.
  • If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.

//-------------------------或者-----------------------------

GetAsyncKeyState

The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call toGetAsyncKeyState.

SHORT GetAsyncKeyState(int vKey   // virtual-key code
); vKey   // virtual-key code
);

Parameters

vKey

[in] Specifies one of 256 possible virtual-key codes. For more information, seeVirtual-Key Codes.

Windows NT/2000: You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information.

Return Values

If the function succeeds, the return value specifies whether the key was pressed since the last call toGetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call toGetAsyncKeyState. The return value is zero if a window in another thread or process currently has the keyboard focus.

//-------------------------------事件函数------------------------------------

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;RECT rec;SHORT res;rec.left = 100;rec.top = 100;rec.right = 700;rec.bottom = 200;hdc = GetDC(hWnd);// TODO:  在此添加任意绘图代码...//str += L"_"; res = GetAsyncKeyState((int)'A');if (res & 0x8000){str += L"A";::DrawText(hdc, str.c_str(), str.size(), &rec, NULL);}res = GetAsyncKeyState(0x42);if (res & 0x8000){str += L"b";::DrawText(hdc, str.c_str(), str.size(), &rec, NULL);}res = GetAsyncKeyState(0x43);if (res & 0x8000){str += L"c";::DrawText(hdc, str.c_str(), str.size(), &rec, NULL);}switch (message){case WM_KEYDOWN:break;case WM_COMMAND:wmId    = LOWORD(wParam);wmEvent = HIWORD(wParam);// 分析菜单选择: switch (wmId){case IDM_ABOUT:DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);break;case IDM_EXIT:DestroyWindow(hWnd);break; default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;
}

//多多指教--

Win32中如何判断多个键同时按下相关推荐

  1. js如何判断鼠标左键是否按下

    JS中判断鼠标按键的问题. IE 左键是 window.event.button = 1 右键是 window.event.button = 2 中键是 window.event.button = 4 ...

  2. matlab中怎么判断一个pushbutton按钮是否按下,matlab的GUI 想问下 每个控件例如pushbutton的函数要怎么编写,函数与普通的m文件一样吗?...

    满意答案 capursuer 2013.05.02 采纳率:47%    等级:12 已帮助:12282人 1.首先我们新建一个GUI文件:File/New/GUI 如下图所示: 选择Blank GU ...

  3. 计算机如何识别这是一个键盘,键盘两个键同时按下时计算机如何识别被按下的是哪个键...

    https://m.toutiaocdn.com/i6831165140000309768/?app=news_article&timestamp=1590675308&use_new ...

  4. containskey java_Java Map.containsKey()方法:判断Map集合对象中是否包含指定的键名

    搜索热词 Java 集合类中的 Map.containsKey() 方法判断 Map 集合对象中是否包含指定的键名.如果 Map 集合中包含指定的键名,则返回 true,否则返回 false. 语法: ...

  5. ArcEngine的鼠标事件中按键判断~

    我们都知道,在.Net的鼠标事件中判断鼠标事件方法如下(以button为例): Private Sub Button1_MouseDown(ByVal sender As System.Object, ...

  6. Python中的判断语句及循环

    Python中的判断语句及循环 文章目录 Python中的判断语句及循环 一.判断(if)语句 01. 开发中的应用场景 程序中的判断 判断的定义 02. if 语句体验 2.1 if 判断语句基本语 ...

  7. jtoken判断是否包含键_Redis 数据库、键过期的实现

    今天看看作为内存数据库,Redis 是怎么存储数据的以及键是怎么过期的. 阅读这篇文章你将会了解到: Redis 的数据库实现 Redis 键过期的策略 数据库的实现 我们先看代码 server.h/ ...

  8. Fragment中设置监听返回键的功能

    首先创建一个抽象类BackHandledFragment,该类有一个抽象方法onBackPressed(),所有BackHandledFragment的子类在onBackPressed方法中处理各自对 ...

  9. android中按两次返回键返回桌面或退出程序

    实现的基本原理 当按下BACK键时,会被onKeyDown捕获,判断是BACK键,则执行exit方法. 在exit方法中,会首先判断isExit的值,如果为false的话,则置为true,同时会弹出提 ...

最新文章

  1. TensorFow的基本使用
  2. 往数据库的表中插入新行
  3. 1-4:CSS3课程入门之文本新增属性
  4. 深度学习--简述卷积层如何检测物体边缘原理
  5. CreateFileMapping共享内存时添加Global的作用
  6. mysql qps如何查看_mysql状态查看 QPS/TPS/缓存命中率查看
  7. 表示探索、探究的几个词
  8. 分析方法的基础 — 1. 拆分能力,分析师的第一技能
  9. 一维战舰(51Nod-1521)
  10. golang | 使用结构体抄的学生信息管理系统
  11. SQL Server如何保证可空字段中非空值唯一
  12. 大数据_Hbase-API访问_Java操作Hbase_获取连接---Hbase工作笔记0011
  13. python json.dumps()函数输出json格式,使用ensure_ascii参数对中文输入的支持
  14. 零基础入门实践目标检测项目
  15. 苹果4s怎么越狱_苹果4S怎么下载东西
  16. js中var self=this的用法解释
  17. 一年工作经验,两周的面试,拿到几个offer的面试经验总结
  18. 信息安全数学基础自学笔记1——群
  19. 【压力测试 2】JMeter压力测试之Internal server error 500 问题解决思路
  20. 十进制和二进制换算。vb版本

热门文章

  1. 预训练语言模型真的是世界模型?
  2. 史上最强多线程面试44题和答案:线程锁+线程池+线程同步等
  3. 论文浅尝 | 用增强学习进行推理:问答与知识库完善(KBC)
  4. Android官方开发文档Training系列课程中文版:管理Activity的生命周期之停止和重启Activity
  5. 当知识图谱遇上推荐系统(总述和推荐)
  6. C#中创建对象的方式
  7. Java Socket NIO
  8. Gym - 100989J -(DFS)
  9. 开发过程中编写的一些批处理
  10. 编程之美--读书笔记--返回一个数组中所有元素被第一个元素除的结果