Non blocking getch()

后端 未结 2 736
忘了有多久
忘了有多久 2020-12-18 00:47

I\'m trying to make Tetris game in standard console. I need non-blocking getch(), so the blocks can fall without pressing any key. It would be nice to have function that ret

相关标签:
2条回答
  • 2020-12-18 00:50

    This is exactly what you wanted:

    int getch_noblock() {
        if (_kbhit())
            return _getch();
        else
            return -1;
    }
    

    Basically kbhit() does the job of determining if a key is pressed.

    Assumes Windows and Microsoft Visual C++.

    0 讨论(0)
  • 2020-12-18 00:58

    It's operating system specific but your library probably has a function called kbhit() or similar that will do this

    0 讨论(0)
提交回复
热议问题