Win32命令行应用,+ReadConsoleInput()得到键盘VK_CODE
2011-10-13 13:50
218 查看
BOOL ReadConsoleInput( HANDLE hConsoleInput, //输入句柄 PINPUT_RECORD lpBuffer, //指向INPUT_RECORD结构体(数组)的指针 DWORD nLength, //上面那个结构体的大小 LPDWORD lpNumberOfEventsRead //实际读入输入内容的个数 );
#pragma once #include <Windows.h>class GohanConsoleHelper { HANDLE _hIn; HANDLE _hOut; INPUT_RECORD _InRec; DWORD _NumRead; public: WORD VKey; GohanConsoleHelper(void){ _hIn = GetStdHandle(STD_INPUT_HANDLE); _hOut = GetStdHandle(STD_OUTPUT_HANDLE); VKey=0; } bool ReadOneInput() { return 0!=ReadConsoleInput(_hIn,&_InRec,1,&_NumRead); } bool ReadOneInput(INPUT_RECORD& InRec) { return 0!=ReadConsoleInput(_hIn,&InRec,1,&_NumRead); } DWORD ReadKeyDown() { if(!ReadConsoleInput(_hIn,&_InRec,1,&_NumRead)) return 0; if(_InRec.EventType!=KEY_EVENT) return 0; if(_InRec.Event.KeyEvent.bKeyDown > 0) return 0; VKey = _InRec.Event.KeyEvent.wVirtualKeyCode; return VKey; } DWORD ReadKeyPush() { if(!ReadConsoleInput(_hIn,&_InRec,1,&_NumRead)) return 0; if(_InRec.EventType!=KEY_EVENT) return 0; if(_InRec.Event.KeyEvent.bKeyDown == 0) return 0; VKey = _InRec.Event.KeyEvent.wVirtualKeyCode; return VKey; } public: ~GohanConsoleHelper(void){} };
#include <windows.h> #include <iostream> #include "GohanConsoleHelper.h" using namespace std;int main() { GohanConsoleHelper gch; while (true) { if(gch.ReadKeyPush()!=0) //使用ReadKeyDown()捕获按键弹起的VK_CODE { if(gch.VKey != VK_ESCAPE) cout<<"VK_CODE == "<<gch.VKey<<endl; else { cout<<"Bye~~"<<endl; break; } } } return 0; }
相关文章推荐
- ReadConsoleInputA no longer works correctly with DBCS in Windows 8.1
- 在命令行处理 console 应用执行的返回值。
- <Win32_3>Bitmap位图应用2 ------ 键盘控制人物走动
- Win32Asm中使用ReadConsoleInput时遇到结构内存对齐
- 键盘记录:vkCode与KeyEvent
- <Win32_3>Bitmap位图应用2 ------ 键盘控制人物走动
- Compile & Run your .apk in console .命令行下编译调试Android应用
- 在命令行处理 console 应用执行的返回值
- showInputDialog 和 showMessageDialog的简单应用~
- 【Linux系统编程应用】 Linux Input子系统(一)
- Android:得到手机上安装的所有应用的名字以及应用所在的包名
- Console.Read();
- Perl命令行应用介绍
- vs2008 web应用中 为什么引用不了App_Code里的类
- 关于动态创建input checkbox的应用
- windows键盘---Win32(zhuan)
- FTP客户端:FTP Client:win32 console appplication
- Android 利用 aapt 解析 apk 得到应用名称 包名 版本号 权限等信息
- Call C# Code from C++ and read an array of struct which contains strings
- Phalcon下命令行应用(command line applications)