How to make a program not wait for input

Jun 20, 2009 at 9:05am
closed account (42hU7k9E)
My program uses getch(); to get input, but the program stops until the user inputs something. I want the program to do other things even if the user does not input anythng. I tried GetAsyncKeyState, it worked nice, but if you pressed a key once, it was like you pressed it twice.
Last edited on Jun 20, 2009 at 9:06am
Jun 20, 2009 at 9:16am
closed account (S6k9GNh0)
Well, you can create another thread I think (I've never made a thread). Other than that, you just need to do everything before you get input.
Last edited on Jun 20, 2009 at 9:17am
Jun 20, 2009 at 10:09am
you could do something like this with GetAsyncKeyState to make it return true only once:
1
2
3
4
5
6
7
8
bool keydown=0;
while(...){
    //do stuf
    if(!keydown && GetAsyncKeyState(...)){
        //do other stuf
    }
    keydown=GetAsyncKeyState(...);
}

Jun 20, 2009 at 10:21am
Last edited on Jun 20, 2009 at 10:23am
Jun 20, 2009 at 11:01am
closed account (42hU7k9E)
Which library do I need to include so the !keydown will work?
Jun 21, 2009 at 3:36pm
closed account (42hU7k9E)
Does any1 have an idea?
Jun 21, 2009 at 4:16pm
'keydown' is just a variable, you need windows.h to have GetAsyncKeyState
Topic archived. No new replies allowed.