pressing enter or any key to disable output delay

Im making an interactive fiction or some sort
and as the title says
is it possible to disable text output delay(sleep) if you press enter or any assigned key?

like in a game (pokemon,etc.)
during conversations you can press 'B' or 'A' to show the texts immediately.

here's my code so far in delaying text output.

1
2
3
4
5
6
  char x[]="Show this text slowly press enter to skip text delay";
for (int i=0;i<sizeof(x);i++)    
{
	std::cout<< x [i];                  
	Sleep(100);
}


it's annoying to wait for all those lines to be outputted (but im keeping it for some sort of effects :P)
Last edited on
It is certainly possible. You have a lot of methods you could use, the easiest is
1
2
3
if (GetAsyncKeyState(VK_RETURN)==0){
     Sleep(100);
}
1
2
3
4
5
6
7
8
9
char x[]="Show this text slowly press enter to skip text delay";
for (int i=0;i<sizeof(x);i++)    
{
	std::cout<< x [i];  
	if (GetAsyncKeyState(VK_RETURN)==0)
	{
                  Sleep(100);
	}                
}


is this right?

i have no idea where i put that sorry lol
i just started learning c++

im pressing enter nothing happens
Last edited on
bump?
So, lets walk through what your code is doing:

1. get the first character in the string
2. output the character
3. check if the Return key is pressed, if it is not pressed, Sleep. If it is pressed, don't Sleep.
4. do it again for the next character in the string until the entire string is output

Now what you want it to do:
1. get the first character in the string
2. output the character
3. check if the Return key is pressed, If it is not pressed, Sleep. If it is pressed, don't Sleep, and don't sleep anymore.
4. output the rest of the string.

Notice if you hold down the Return key it quickly outputs the rest of the string, right now you are checking for each letter if the Return key is being pressed.
that's exactly what im trying to do
any idea how? :(
Once the Return key has been hit you could set a flag(just a bool) and check that if the flag has been set before you call Sleep().

Give it the old college try once more and post whatever you come up with.
Topic archived. No new replies allowed.