• Advertisement
Sign in to follow this  

[C++] Immediate reaction after receiving input from keyboard.

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again, I've run into this little problem. I need to be able to extract what someone wrote into the console without him pressing ENTER, for example when asked to press y or n, as soon as the user presses the button some action is taken, instead of having to wait for him to press the letter and then press enter. I've tried to look for solutions to this in the iostream library, but none of the methods in the cin object seem to do what I need. How would I go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
The C++ standard library has no support for this. You'll need to look at OS specific functionality (such as kbhit() and getch()) or third party libraries (like ncurses or pdcurses).

Share this post


Link to post
Share on other sites
Ah, didn't think this was so easy. _getch() does the job just fine. Thank you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement