🔒 Locked
GetKeyState( ) Help
Advertisement
Original Post
i was wondering if there is any way i could use this function to fire a procedure only once, EVEN THOUGH THE KEY IS STILL BEING HELD DOWN. so in order to fire the same procedure again, one would have to let go of the key and press it again. its really annoying, i've been trying to figure it out but i cant. plus, having to only hold a key down to fire an endles stream of lasers towards the enemy gives the players of my game a big unwanted adavantage ;) i want for them to press a key every time they want to fire a laser so its harder. any ideas? i'm using Visual Basic 6. Thanks.
Quote:
Original post by aaj2006
i was wondering if there is any way i could use this function to fire a procedure only once, EVEN THOUGH THE KEY IS STILL BEING HELD DOWN. so in order to fire the same procedure again, one would have to let go of the key and press it again.
its really annoying, i've been trying to figure it out but i cant. plus, having to only hold a key down to fire an endles stream of lasers towards the enemy gives the players of my game a big unwanted adavantage ;)
i want for them to press a key every time they want to fire a laser so its harder.
any ideas? i'm using Visual Basic 6. Thanks.
In the WindowProc, you can check whether a specific key has been set (I use space in my example) and fire accordingly to if it's set or not. I cannot write it in VB code, but I'll hop you get the point from my C++:
bool shoot_key = false;LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg) { case WM_KEYDOWN: if (wParam == VK_SPACE && shoot_key == false) { fire_laser_event(); shoot_key = true; } break; case WM_KEYUP: shoot_key = false; break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); }}This way the player has to let go before he/she can fire another time. Although I would prefer that you could only shoot every 250 ms (4 per second) or something like that, because tapping on a specific key is quite painful after a while - but of course if you need tapping, then your skills would depend much more of you :-P
EDIT: I can also write most of it in pseudo code if you want ;-)
[Edited by - nife on April 16, 2005 7:46:54 AM]
I imagine VB6 doesn't have a WindowProc. At least that was how it was when i last did vb.
If you are using GetKeyState() then you could simlpy remember whether or not the laser has been fired and only allow a refire once the key has been depressed:
As far as I can see this would prevent more than one laser fire per key press
If you are using GetKeyState() then you could simlpy remember whether or not the laser has been fired and only allow a refire once the key has been depressed:
keystate = GetKeyState(FIREBUTTON)if keystate = KEYDOWN then if alreadyFired = false then FireLaser() alreadyfired=true endifelseif keystate = KEYUP then alreadyfired=falseendifAs far as I can see this would prevent more than one laser fire per key press
sorry about my lack of memory of vb syntax
Thanks Guys.
Running, your idea sounds good except that i would have to wait for that same laser to either hit the target or go outside of the play area for it to be available for fireing again. and since the lasers dont move very fast, there would be a big time interval between every shot. in this time, the enemy would have already fired 6 lasers. i need something like what nife sugested, only for VB6.
Thanks again.
Running, your idea sounds good except that i would have to wait for that same laser to either hit the target or go outside of the play area for it to be available for fireing again. and since the lasers dont move very fast, there would be a big time interval between every shot. in this time, the enemy would have already fired 6 lasers. i need something like what nife sugested, only for VB6.
Thanks again.
well, no i'm not just reposting the same laser...
i have an array of 13 shape controls that i fashioned into long beams. then i have an array of 13 boolean variables, one for each laser. basically, if the boolean is set to true, then the laser has been fired and is moving up detecting collisions and all that, but if its false, it goes back to its place, waiting to be fired.
the problem is in the GetKeyState() area. what i want is for there to be a counter in LaserFire() so when i press the key, it checks the counter. if the counter is set to 3 for example, it will fire its respective laser beam, Laser(3) and add 1 to the counter, so when i press the key next time, it will fire laser 4 and add 1 to the counter again and so on. but GetKeyState() fires the event continuously while the key is being held down, so obviously it will shoot too fast for the game to be enjoyable. all i need is some way to fire the procedure only once, regardless of weather the key was held down or not after it was pressed so in order to redo the process, you would have to lift the key and press it down again.
i hope you have a better understanding of my problem now and can help me with it.
thanks.
i have an array of 13 shape controls that i fashioned into long beams. then i have an array of 13 boolean variables, one for each laser. basically, if the boolean is set to true, then the laser has been fired and is moving up detecting collisions and all that, but if its false, it goes back to its place, waiting to be fired.
the problem is in the GetKeyState() area. what i want is for there to be a counter in LaserFire() so when i press the key, it checks the counter. if the counter is set to 3 for example, it will fire its respective laser beam, Laser(3) and add 1 to the counter, so when i press the key next time, it will fire laser 4 and add 1 to the counter again and so on. but GetKeyState() fires the event continuously while the key is being held down, so obviously it will shoot too fast for the game to be enjoyable. all i need is some way to fire the procedure only once, regardless of weather the key was held down or not after it was pressed so in order to redo the process, you would have to lift the key and press it down again.
i hope you have a better understanding of my problem now and can help me with it.
thanks.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement