Hi Thomas,

getchar is, as you know, about as basic as you can get but at least it is standardized. getch is not, nor would a custom pseudo getch hack be. It's bound to exhibit different behavior on various platforms and you'd have to have access to all of them to verify. If you want immediate reactions without the need to wait for a return keypress, have you considered using something basic such as the keyboard handling in SDL in your console window? Then you can suddenly treat the keyboard in a similar fashion to what you would do in a regular non-console game, but do it portably. SDL has received a major rewrite in version 2.0 and is now under the Zlib/Libpng license which is very commercial friendly.

Kind regards,

Philip Bennefall
----- Original Message ----- From: "Thomas Ward" <thomasward1...@gmail.com> To: "Philip Bennefall" <phi...@blastbay.com>; "Gamers Discussion list" <gamers@audyssey.org>
Sent: Thursday, April 17, 2014 1:30 AM
Subject: Re: [Audyssey] Pausing the Screen in Console Programs


Hi Philip,

Well, as I explained in a previous post I know about getchar, and
unfortunately it isn't quite what I am looking for. Besides pausing
the screen I want a function that will act upon a key immediately
rather than waiting for the enter key which getch does and getchar
won't.

However, I have found getchar doesn't always work when pausing the
screen anyway. I have written the following function in C++, and it
fails to do what I want which is to pause until the enter key is
pressed.

void WaitKey()
{
   std::cout << "Press enter to continue:\n";
   std::getchar();
}

Now, in theory that function should prompt the user to press the enter
key and pause the game until the enter key is pressed. Sometimes it
does and sometimes it doesn't. I have written a test program using
getchar as written above and there are cases where the program ignores
the WaitKey() function I wrote and goes and executes the next function
regardless of my instruction to wait. So I don't think pausing the
screen with getchar is necessarily a valid method for cross-platform
pausing the screen. Of course, there may be a difference between the C
implementation of getchar in stdio.h and the C++ implementation in
cstdio. Not sure if that is a difference or not.

Cheers!


On 4/16/14, Philip Bennefall <phi...@blastbay.com> wrote:
Hi Thomas,

I tend to find that getchar suits my needs perfectly. Making a call to
getchar and ignoring the return value does exactly what you describe, and in

a portable way. getch is non-standard as you know so may or may not be
present on any given target.

Kind regards,

Philip Bennefall


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to