This question already has an answer here:
And I know there's std::cin
, but that requires the user to enter a string, then press ENTER. Is there a way to simply get the next key that is pushed without needing to press ENTER to confirm
This question already has an answer here:
And I know there's std::cin
, but that requires the user to enter a string, then press ENTER. Is there a way to simply get the next key that is pushed without needing to press ENTER to confirm
You can use
and then catch char with cases such as this
Beware: I have not tried it... and remember to put the whole thing into a "while(true)" to test.
It looks like the most upvoted answer is a bit outdated.
The ncurses library (based on the mentioned curses library) is a portable implementation available for unix and linux based operating systems, windows and others.
It supports a wide variety of terminal interfaces.
What you're looking for is related to manipulating the console, and is OS-dependent. If you're in a UNIX-based OS, check out the curses library, and in Windows, there are
getch()
andkbhit()
functions from<conio.h>
.