key in function

hey, if i want a user to press a keyboard key(like "k") anytime during a loop so something will happen in addition to everything else in the loop,
how do i do that?

like
1
2
3
4
for(int a=0; a<100; a++){cout<<"somthing";
//if user press K
//cout<<"more something";
}
If you use Windows, you can use the GetAsyncKeyState() function call from <windows.h> . Otherwise, use getch() from <conio.h>

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx
Last edited on
i did not understand how to use it from this mdsn website. can you give me an example how to use it please?
Topic archived. No new replies allowed.