Pressing buttons to continue

Jul 21, 2009 at 5:24pm
Hello, i've been curious to know...
i've seen programs where it says:
Please press shift to continue

or:
Do your wish to continue? (press y/n)


Basically, my real question is,
how do you make a program where you press a certain button without pressing enter or actually needing to input text or something?

Jul 21, 2009 at 8:24pm
Well, getch() will do it, but it's not in the standard so its considered a bad practice.
Jul 21, 2009 at 8:54pm
It depends on the key you want to react to and what your platform is.

getch() probably won't work if you are looking for shift/alt/ctrl/caps lock keys because those
keys are not passed to the user application by the OS.

For other keys, it depends on the platform.

For unix, for example, you can turn off line buffering on stdin via termios.
Jul 21, 2009 at 11:07pm
so your saying the the code i would use to do that would depend on the platform of your pc?



and also, can you do what i was talking about in my question using
getline() ?


Jul 21, 2009 at 11:50pm
getline() by definition will read characters until it encounters a newline (ENTER).


Jul 22, 2009 at 1:15am
well then how does this work?

isn't there like a default code used for this stuff... or does it depend on what key I want the user
press?
Jul 22, 2009 at 11:48am
See my first response. What platform are you using?
Jul 22, 2009 at 12:50pm
See also
http://www.cplusplus.com/forum/articles/7312/page1.html#msg33734

The first part of the article also covers NCurses and conio...

Basically, what you want to do is turn off line-buffered input.

Hope this helps.
Jul 22, 2009 at 7:44pm
I'm using a windows platform...
Jul 23, 2009 at 1:58am
Well, how convenient that the very first example I gave in the link is for the Windows platform.
Good luck!
Topic archived. No new replies allowed.