#include <windows.h>
#include <iostream>
using namespace std;
bool getconchar(KEY_EVENT_RECORD& krec)
{
DWORD cc;
INPUT_RECORD irec;
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
if (h == NULL)
{
return false; // console not found
}
for (; ; )
{
ReadConsoleInput(h, &irec, 1, &cc);
if (irec.EventType == KEY_EVENT
&& ((KEY_EVENT_RECORD&)irec.Event).bKeyDown
)//&& ! ((KEY_EVENT_RECORD&)irec.Event).wRepeatCount )
{
krec = (KEY_EVENT_RECORD&)irec.Event;
return true;
}
}
return false; //future ????
}
int main()
{
KEY_EVENT_RECORD key;
WORD Aimkey = NULL;
for (; ; )
{
getconchar(key);
std::cout << "key: " << key.uChar.AsciiChar
<< " code: " << "0x" << std::hex << key.wVirtualKeyCode << std::endl;
}
}
输出:
key: m code: 0x4d
key: a code: 0x41
key: s code: 0x53
key: d code: 0x44
mouse ???