I'm trying to write a function that pauses a game when 'p' is pressed, and then resumes when 'p' is pressed again. Here's what I wrote, but it works only for a long press of 'p' to start the pause (I guess it's because I can't capture the exact moment of the key press). Could you please tell me what adjustment to make so it would work right? Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
bool pause_state=false;
if (kbhit()) {
if (GetAsyncKeyState(0x50)==true && pause_call==false) {
pause_call=true;
Sleep(700);
while (!GetAsyncKeyState(0x50))
Sleep(1);
pause_call=false;
}
}
269 C:\Dev-Cpp\Projects\Pr\str.cpp case label `258' not within a switch statement
270 C:\Dev-Cpp\Projects\Pr\str.cpp `wParam' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)