Detecting keystrokes

前端 未结 3 880
清歌不尽
清歌不尽 2020-12-17 04:05

I need to detect a keystroke, without the user pressing enter. What\'s the most elegant way?

I.e. If the user hits the letter Q, without pressing ent

3条回答
  •  清酒与你
    2020-12-17 05:05

    Theres no good way to do this portably, as far as I know, other than to use a library like ncurses, which provides the getch(void) function.

    Note: It appears getchar(void) from stdio.h waits until the enter key is pressed then feeds your the characters,s o it won't work.

提交回复
热议问题