Console non-Blocking Input | 控制台非阻隔輸入

有些時候(特別是控制台遊戲)並不希望程式因為等待用家的輸入而停止執行,這時可以使用_kbhit() 檢查鍵盤輸入和 getchar()取得輸入字元。

Sometime, input is needed without any stop when the program running loop(e.g. cmd-line game). At this time, we may try to use _kbhit() with getchar().


#include <conio.h> 

while (true) {
        if (_kbhit())
            ch_keyPressed = getchar();
        /* Your code*/
}

留言

此網誌的熱門文章

[OpenCV] RAW rgb data to IplImage | 以rgb原始資料建立IplImage指標

Monitoring System Spec.& IO Mapping

突如奇來的高科技電子零件