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().
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*/
}
留言
發佈留言