【发布时间】:2020-05-12 20:22:45
【问题描述】:
if (a == 1) {
cout << "Press a" << endl;
Sleep(500); // I tried to do it this way but it didn't work
if(GetKeyState('A') & 0x80000){
cout << "Nice" << endl;
}}
我没有足够的时间按键,也许你有什么解决办法。
【问题讨论】:
-
如果您打算像这样将所有内容保存在一个线程中,我强烈建议您切换到State Machine Design。
-
GetKeyState反映了上次处理消息时的键盘状态,并且您的循环未处理任何消息。请改用GetAsyncKeyState。请注意,您必须在调用函数的确切时间按住键才能看到它。