How to get a keypress event in the console

I am learning C and have a problem getting on_key_press_event without pressing Enter. And of course I need a character code. Is there a solution?

+4
source share
2 answers

I recommend reading here . I think,

getchar() 

may be what you need.

EDIT: Actually possible

 #include <conio.h> _getch() 

will work better for you, since it does not require a line break character (enter the button that will be pressed). For windows, refer to this and for unix systems, this seems to be included in the curses library .

Hope this helps!

+7
source

There is no cross-platform way to do unbuffered input from stdin. You can use curses if you are using a Unix-based distribution. On Windows, you can use getch .

+5
source

All Articles