NeHe key press handling code not working properly
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.
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]
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.
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.
that's exactly how i'm doing it.
that's copied directly from my winproc.
[edited by - deathtrap on July 23, 2003 2:28:10 AM]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement