Simple Console IO Question
I'm programming a text-based game, and am having trouble with the "Press enter to continue" scenario. Occasionally, the user will press enter once and it will act as though it was pressed several times, overflowing into the other inputs. How can I fix this?
Right now, I'm using this little routine:
getchar();
You have to use some kind of timer that disables the enter key for a short time, long enough for the user to have time to let go of the key and short enough for it to never show, sort of like this
delay+=t;
if (delay>1) delay=1;
if ((g_keys->keyDown [VK_RETURN]) && (delay>0.2))
{
--do whatever--
delay=0;
}
t is the delta time for each frame(or loop in your case), t=1 is a second.
alternatively you can check if the key is pressed down and then released instead of just pressed down.
delay+=t;
if (delay>1) delay=1;
if ((g_keys->keyDown [VK_RETURN]) && (delay>0.2))
{
--do whatever--
delay=0;
}
t is the delta time for each frame(or loop in your case), t=1 is a second.
alternatively you can check if the key is pressed down and then released instead of just pressed down.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
I know that if you are using scanf() anywhere in your program, getchar() will register the enter key that signifies the end of input. You can get around this by using a dummy input right after your intended input.
scanf(szText, "%c") ;
scanf(szDummy, "%c") ;
scanf(szText, "%c") ;
scanf(szDummy, "%c") ;
-----------------------------------Indium Studios, Inc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement