Archived

This topic is now archived and is closed to further replies.

scubabbl

KeyPress Problem

Recommended Posts

Okay, so Im a noob, and figure I would start out with a simple pong game. No problem doing the graphics really, but, I am having a problem with Key Press issues. I have if WM_KEYDOWN to check which keys people are pressing to decide which way to move the paddle, but, I find, in two player, if one person is holding down a key, the key the other person is holding down won''t work. How should I fix this problem? -Jason

Share this post


Link to post
Share on other sites
the eaay way is that you could use an array of bools, and set the ines that are down to true, the hard way IMHO is learn direct input. I like easy things, so i'll give ya some code to that effect


ie (taken from NeHe tutorials but not specific to OpenGL)
    
bool keys[256]; Array to hold all the keys we've got

and add this to your WndProc Callback

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

}



edit: Note that in my experiance this can only handle about 4 or 5 keys at one time... and it depends on which keys... i think that has something to do with the way keyboards send data... i'm not realy sure.

-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny

Edited by - Authustian on November 2, 2001 9:31:23 PM

Share this post


Link to post
Share on other sites