Dustin Burns
Dustin Burns

Reputation: 203

If loop that executes when Enter key is pressed C++

I'm using Windows XP Home Edition. I want to set up a menu system that displays an image when the Enter key is pressed. Is there any way I can set up an if statement that executes when the Enter key is pressed on the keyboard without setting up a GUI. For example, can I just use the hex value associated with Enter key as a trigger for the if statement.

I've looked into reading input buffers. Am I going to have to get that complex with it? I don't really

Upvotes: 0

Views: 141

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409356

For windows there are a couple of variants you could use to implement this:

  1. The standard way would be to call e.g. std::getline and discard the input.
  2. A more Windows-specific solution is to use e.g. _kbhit and _getch to check for the Enter key.

Upvotes: 1

Related Questions