How could I make my program switch Sleep() while enter is pressed?
I was thinking of a small rpg to write for fun, and I stumbled upon a question... Here's the problem:
Code:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
string intro_speech = "Hello, and welcome to the introduction of this RPG!";
for(unsigned i = 0; i < intro_speech.length(); i++)
{
cout << intro_speech[i];
Sleep(100);
}
return 0;
}
So basically, what this simple program does (so far) is outputs the string "intro_speech" character by character, hence the for loop, with a 100 millisecond delay inbetween each character. But what I wish to do is while it's outputting it, if the user clicks ENTER it will change the 100 millisecond to 0 milliseconds, thus instantly outputting the rest of the string.
I was thinking of maybe putting a "while" or "while...do" loop inside the FOR loop, but I'm not sure how to make the program pick up the enter key being pressed without using cin.get() which issue #1: Stops the continous output of string "intro_speech", making the user press enter after each character; issue #2: I would rather like the argument decision influenced by whether cin.get() equals to true or false at each moment of time until the loop is over , which, I have know idea how to check if cin.get() equals to true. Whether its even possible to check cin.get() for that, I honestly have no clue.
The code I posted above has been edited of my horrific 'while' and 'do...while' loops.
Any advice or tips would be greatly appreciated! Thanks!