I've got female keys, way too sensitive...
Disclaimer: This topic is only for what little comedic value it may add for some people and may not refelct the real feelings of this poster.
Hey, I''m having a perplexing problem with my key events. I have a controller class which handles my windows events. Anyway hey has a HandleKeys() function. In that he checks using a KeyDown() inline member function which is just that async thing everyone seems to be using.
ANYWAY, it''s REALLY sensitive, like I have a problem getting it to go off ONCE, and it probably just went off an odd number of times (it''s for a togglable option). I moved the function call into my timer set static FPS loop, but 30 times a second is still too fast.
So, i''m just wondering how other people tackle this problem. I don''t want to check for key down then key up because I hate having to lift off keys before the option works, just a short pause before the next firing would be nice, but it shouldn''t stop the other keys from fireing. hrm =)
Hope this is clear enough!
- Newb Programmer: Geek++
well, what I would do in your situation is to make whatever procedure you're tring to only fire once take care of itself. In my opinion, the more sensitive the key detection, the better, makes for a more responsive game ... but you could do something like
C#
That way, if the FireWeapon gets called a bunch of times, it will only fire once until the whole procedure is done.
--edit: added the try finally to make sure _isFiring gets set to false regardless of what happens in the try block, just couldn't live with myself ;-)
Hope that helps,
Joel Martinez
http://www.codecube.net/
[edited by - joelmartinez on January 4, 2004 9:37:23 PM]
C#
private bool _isFiring = false; public void FireWeapon(){ if (!_isFiring) { try { _isFiring = true; //fire! } finally { _isFiring = false; } }}
That way, if the FireWeapon gets called a bunch of times, it will only fire once until the whole procedure is done.
--edit: added the try finally to make sure _isFiring gets set to false regardless of what happens in the try block, just couldn't live with myself ;-)
Hope that helps,
Joel Martinez
http://www.codecube.net/
[edited by - joelmartinez on January 4, 2004 9:37:23 PM]
I think what you want is to make a distinction between OnKeyDown, IsKeyDown, and OnKeyUp.
Store the state of all the keys for the current frame and the previous frame in an array. If the previous key state was up and it is now down then fire all of the OnKeyDown events, if the key was up and now is down then fire all of the OnKeyUp events. Then have IsKeyDown check the current state of the keys and report that.
-SniperBoB-
Store the state of all the keys for the current frame and the previous frame in an array. If the previous key state was up and it is now down then fire all of the OnKeyDown events, if the key was up and now is down then fire all of the OnKeyUp events. Then have IsKeyDown check the current state of the keys and report that.
-SniperBoB-
Or, you could make a timer to allow only so many shots per interval:
int Time=0; // being global in a file//in your fire functionif (GetTickCount()-Timereturn;else{//fire code hereTime=GetTickCount();}
have some bool allowmove/allowfire whatever that is set to false when the key is pressed and then set to true again after a certain time
msdn for GetTickCount() if you havnt worked with time...
msdn for GetTickCount() if you havnt worked with time...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement