Advertisement

NeHe key press handling code not working properly

Started by July 22, 2003 11:43 PM
9 comments, last by deathtrap 21 years, 7 months ago
Hi, NeHe''s method for handling key presses doesn''t seem to be working for me. It sets the correct element in the keys array for the WM_KEYDOWN message, but it never unsets it with WM_KEYUP. so basically my input handling code keeps thinking that i''m still holding down the key even when i''ve long since released it. I have no idea what is wrong. I''ve been left with two options, either handle each VK_* message in the WM_KEYDOWN section, which can get very messy, or write my own input handler using GetAsyncKeyState, which I found easy to implement except that I think it might be costly considering I would have to call GetAsyncKeyState for every key i want to check, when that information is already available to me in the WM_KEYDOWN message.
you''re doing something wrong, it works.
Advertisement
case WM_KEYDOWN:    m_Keys[wParam] = true;    break;//case WM_KEYUP:    m_Keys[wParam] = false;    break;//


That should save you a lot of headaches.

EDIT:
Make sure your using it like a boolean to:
if(KeyDown(VK_RETURN))
{
ProcessSomeCode;
}

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on July 22, 2003 12:49:05 AM]
Post some code the method does work...
The monkeys are listening...
Make sure you have it set up like this:

switch(message){
case WM_KEYUP:
keydown[wparam] = false;
break; // NEEDED TO EXIT SWITCH

case WM_KEYDOWN:
keydown[wparam] = true;
break;
}

if you forgot the break command at the end of the WM_KEYUP case, the program will follow through with executing the WM_KEYDOWN case, thus seeming as if the key is always down after it has been released.
Bah curse you guys :D
Advertisement
that's exactly how i'm doing it.

switch (msg)	{	case WM_KEYDOWN:		{			keys[wParam]= true;			break;                }        case WM_KEYUP:                {                        keys[wParam]=false;                        break;                }        }


that's copied directly from my winproc.



[edited by - deathtrap on July 23, 2003 2:28:10 AM]
That''s right. Now stop complaining and go do something useful.
But the WM_KEYUP message is never recieved.
Hmm, scratch that, apparently it''s recieving both WM_KEYDOWN and WM_KEYUP, but after it recieves one, it floods it with messages of the same type, so if i press the L key, after i release it , it''s flooded with both WM_KEYUP and WM_KEYDOWN messages. wtf?

This topic is closed to new replies.

Advertisement