Hi, I'm trying to create a loop that keeps going until the user presses a key, I'm currently using _getch() which pauses the thread until there's an input, which I don't want. I've tried using _getch_nolock() but the same thing still happens, here's the script I'm trying to use:
IMHO you should not continuously poll for keyboard input, because it would use 100 percent of the CPU for nothing. If tell us more about what problem you are trying to solve, we might come up with a better solution.
But if you really want to do what you say, the solution will probably be platform-specific, so we need to know which platform you are working on.
im trying to detect when there's an input to move a character (in this case a dash) across the screen when a certain key is pressed, im trying to do this to create a simple pong style game. im working on windows xp with visual c++ 2008.
Using a delay is better because it allows the system to handle your thread much more nicely... and has no noticable effect against your program.
Make sure to read the input once you know that a key is pressed.
Hope this helps.
[edit] Wait, you're using using VS2008? How exactly are you doing this: as a GUI application or a Console application? If you are using a GUI application, you should be listening for key events in your main form. If it is a console application, you should be familiar with the Windows Console Functionshttp://www.google.com/search?btnI=1&q=msdn+Console+Functions [/edit]
i just started as an empty project, i guess its a console application. i dont really understand the functions you linked me to, the one that seems to look like a good idea is ReadConsoleInput but i have no idea how to use it, also i would like my application to do something while waiting for an input, i guess the easiest way to do this is with multithreading, but im still not sure how to that, the only thing i know is in windows you use _beginthread but is there a better way than this e.g. writing my own function to do it, or a better library. any examples would be brilliant.