hey im trying to make a program that loops though numbers until you hit return, im doing on a console program and im not using cin. Does any one know how this can be done?
Thanks
Printable View
hey im trying to make a program that loops though numbers until you hit return, im doing on a console program and im not using cin. Does any one know how this can be done?
Thanks
Code:
#include <windows.h>
....
for(;;){
if(GetAsyncKeyState(VK_RETURN))
break;
}
...
Ack... 100% CPU usage. :(
Why are you writing a console program and not using i/o functions/objects?
Damn..
i just wanted to know how to stop a loop when someone presses a key.
Given that you have a message loop:
Of course this only works if the loop is in a different thread.Code:while(g_bRun) {
// ...
}
// WndProc:
case WM_KEYDOWN:
g_bRun = false;
break;
For console apps, this works for me:
but it is absolutly not what a console app is intended for.Code:while(GetAsyncKeyState(VK_RETURN) == 0) {
cout << '.';
Sleep(100);
}
cout << "\nDone." << endl;