因此,我使用GetAsyncKeyState()來查看何時按下某個鍵。但是,在使用它之後,我需要使用getch()。但似乎getch()再次得到GetAsyncKeyState()得到的任何東西。這是我簡化代碼的版本:如何在使用getch()之前清理輸入緩衝區?
#include <graphics.h>
int main()
{
initwindow(100, 100);
while(true)
{
if (GetAsyncKeyState(VK_RETURN)) //wait for user to press "Enter"
break;
//do other stuff
}
getch(); //this is just skipped
return 0;
}
我想我需要在使用getch()之前清理輸入緩衝區。但是如何? PS:GetAsyncKeyState()是我必須使用的,我還沒有找到任何替代getch(),它可以與BGI窗口一起工作,並且可以解決問題。 希望得到一些建議,謝謝。
很抱歉,但它似乎並沒有工作。即使我在fflush之前放置Sleep(1000),應用程序仍會跳過getch。 – user3496846