I'm just learning how to use GetCh(). I have the GetCh() call inside a do...while loop and I think I'm having a problem where sometimes the program is not waiting for the user to press a key, instead it is using the same key that was pressed the last time GetCh() was called and continuing on until GetCh() is called again in the next time through the loop.
My actual code is quite long, so I don't want to bore you guys with it, but this is an approximation of what I have:
However, when I use this code, I notice when I'm debugging it that the character located at *KeyPress is the inputted character followed by a series of garbage characters. Though, the code still functions, I believe this is probably sloppy coding. Can anybody help me clean this up or tell me what I'm doing wrong?
I don't actually understand any of the code in the CHAR GetCh (VOID) function. I just copied and pasted it from a forum post from somebody suggesting a good way to get keyboard input without echo. Is there a way to adjust this so it is looking for a char instead of a string?
It is starting to get large (over 350 lines in int main() )
I'm using the wads keys to move the player around the board. I haven't proven it yet, but I'd swear that sometimes when I press a direction he jumps ahead two spaces instead of one. Is there maybe a way to flush the input buffer before checking for input the next time the loop comes around?
...and your platform supports c++11 style coding
I'm not really sure what that means or how I check. Do you mean what OS I have (i.e. Windows 7) or what compiler I'm using (i.e. Visual Studio 2010)?
I've been doing a bit more testing and now I am definitely getting occurances of the program skipping where it's supposed to wait for keyboard input from the user and instead running through the loop again using the KeyPress value from the previous loop. Any ideas?