I've got a picture. Whenever I press the down key, the picture will go down. The problem is, I want it to response as even though I press and hold the down key, it will only move one step!
How do I do that?
Printable View
I've got a picture. Whenever I press the down key, the picture will go down. The problem is, I want it to response as even though I press and hold the down key, it will only move one step!
How do I do that?
assuming u mean u want it to keep going even after u lift the key...
dim keypressed as boolean
private sub form1_keydown(keycode as integer etc...)
if keycode = 40 then keypressed = true '40 is down right?
end sub
private sub timer1_timer
if keypressed = true then object1.top = object1.top + 1
end sub
this should make it always go down after u rpessed it, if u want ti to stop when u release the key, add
private sub form1_keyup(same as keydown i think)
if keycode= 40 then keypressed = false
end sub
That will probably work in a simple game. But in my experiance if your codeing a complex game that requires the programe to sense someone holding the key down for a long time, its much better to use Direct X 's, Direct Input aspect anything else I tryed useing gave includeing GetAsncKeyState() gave me some occasional weird gliches. Its really easy to use too if you want that code e-mail me [email protected]
Thanks all. One more though. Is there a way to no matter how long the keydown is pressed and hold it will only move one step.
Anyone?
As the other guy said, use the API call:
GetAsncKeyState()
then have som boolean switch that changes when GetAsncKeyState() is different from its previous value.
To check it against a previous value, just use another variable. I.e
a = GetAsncKeyState(40)
......Insert code
if GetAsncKeyState(40) <> a then BoolSwitch = NOT(BoolSwitch)
a funny question.....
no matter how many times I tried the easy method by alkatran, if I would leave out the keyup procedure, the character still does not keep moving! Can someone then post the whole coding for it.
under form1's keydown:
If Keycode = vbkeypress then object.top = object.top + 1
may also be keyascii.. I dunno.. make sure if it is in the sub.
that (if i did it right, don't have VB installed ATM..) will make it move only once, no matter how long you hold it