Skip to main content
GameDev.net gamedev.net
🔒 Locked

keyboard handling

Started by mfdemi Dec 7, 2002 at 11:15 AM 0 replies 550+ views
Original Post
mfdemi
mfdemi
I test keyboard input in the WndProc funtion like the following: case WM_KEYDOWN: // Is A Key Being Held Down? { Keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } case WM_KEYUP: // Has A Key Been Released? { Keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } And in the main function I check for certain keys ever frame.But this doesn''t seem to be sensitive enough.For instance when the user presses the PAUSE key I want to pause the game.But not every time it happens.
LordLethis
LordLethis
I think it is executed every time, but since you check every frame for the key, you''ll be executing your PAUSE-code multiple times. You could use a boolean to indicate whether the key is being pressed. Set it to 1 (=true) when executing the PAUSE-code, and if it is released, set it to zero (=false) again.

  
bool pp = 0; // indicate whether pause is being pressed

.
.
.
if (Keys[VK_PAUSE] && !pp)
{
pp = 1;
//your code

}
if (!Keys[VK_PAUSE] && pp)
{
pp = 0;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.