0
I’m writing a program that reads an indefinite number of keyboard values and stops only when the user presses Esc.
I tried to solve this using the function GetAsyncKeyState()
as follows.
#include <Windows.h>
if (GetAsyncKeyState(VK_ESCAPE)){
for(int i=0;i<=n;i++){
cout<<v[i]<<endl;
}
return 0;
}
But even after squeezing Esc the program only goes to the for
after I enter some other number.
How does the program jump to the for
right after I squeeze Esc?
We’re missing a
}
there.– CypherPotato
I believe your program is stopping at another loop that only comes out when you press a number. The call
GetAsyncKeyState(VK_ESCAPE)
at all times will return non-zero if ESC is pressed. I suggest isolating the failed code or posting your entire code here in the OS.– Fernando Silveira