-
input without pause
I have a while loop that i want to keep going until the user presses enter, i have tried using
while (getch()!=13)
{
commands
}
and other variations, but every command i know pauses the loop and waits for the input. Is there a way to keep the loop going while also waiting for the input?
any help would be greatly appreciated.
-
the way I used to do it way back when I did games in the console was to use kbhit() which returns true if any key on the keyboard has been hit. Not sure if it's a standard function or not though, might have to look that up
Code:
int done=0;
while(!done)
{
if(kbhit())
{
int keypress=getch();
if(keypress==224)
{
int subkeypress=getch();
// Process arrow keys, f1-f12 keys, etc
}
}
// Process the rest of the program here
}
-
oh, there's also asynchronous key getting using this function:
GetAsyncKeyState
It might be best to pair it with this macro, unless you're against macro use.
Code:
#define KEY_DOWN(vk_code) ((GetAsyncKeyState((vk_code))&0x8000 ? 1:0))
and btw, you have to pass a VK_* code here, so you could do:
if(KEY_DOWN(VK_RETURN))
to test if the return/enter key has been pressed
(defined in windows.h)
-
Thanx
sweet. thanx for that, works like a dream.