-
Hey Im using (getkeystate) api for input and what I want to do is when some 1 presses space the Speedometer accelerates(This I can Do) but how can I make it so when space isn't pressed it will perform my deceleration. Please dont tell me to use Key_press and Key_Up.
Thanks
-
Use a timer, and in your timer sub:
Code:
If key_is_pressed Then
speed = speed + accel
else
speed = speed - decel
end if
-
Sorry
Sorry that wont work cause there is going to be at least 5 more keys. Let me say Id like to use getkeystate api, cause Im familiar w/ it.
-
Just check the key state for each key individually in the timer procedure. You can use GetKeyState if you want.
-
Another Prob
Private Sub mainloop()
Do While DoEvents
If (GetKeyState(vbKeySpace)) Then
Label1 = "Up"
end if
If (GetKeyState(vbKeySpace)and key_down)
Label1 = "Down"
End If
Loop
End Sub
This was just a test but it works except for when you hold space and release.It only works if you tap space. Any idea?????
-
1 Attachment(s)
This is sort-of-what-I-mean. I expect you can adapt the code from that:
-
How bout you do the if...then..elseif...endif statement and put in all your buttons, and at the end put in else, and then decelerate there.
-
First look at this project (save as..), if it's what you need read THIS. :rolleyes:
-
Create a couple of Booleans for each key. when you detect that Key X has been pressed (however you want to do it), set Boolean X to TRUE. Then, in your loop, just update accordingly, then get the keystates again. When its off, then set the Boolean to FALSE. XOR might help with this, for testing if the key should be switched.
Code:
If FIGetKeyStateFunction(KeyX) Xor KeyXIsDown Then
KeyXIsDown = Not KeyXIsDown
End If
Z.
-
Fox......
Fox I think your way is the best. But how come you need to show Me before you can call the loop. This is something that has puzzled me for years(not really).
-
Actually
I just checked Sastraxi's way and his is best...and its the easiest way!
-
HA!
Beat you fox! hehe ;)
j/k
-
Yeah :)
Main thing is we could help him :P
-
I know that... I think...
-
You have to call Me.Show, because when the main loop is in form_load, all code in the sub is executed BEFORE the form is shown. If you dont tell it to show the form first, nothing will appear to happen.
Z.