using the keydown function in a timer
hi, I am making a game that involves using the arrow keys I have been using the keydown function for the form but when i use it now all the timers seem to stop. this was my previous code for the arrow keys using the keydown function:
Code:
If e.keydata = keys.up Then
If pbxship.Top <= 77 Then
pbxship.Top += 10
Else
pbxship.Top -= 10
End If
ElseIf e.keydate = keys.down Then
If pbxship.Top >= 800 Then
PbxLazer.Top -= 10
Else
pbxship.Top += 10
End If
now i am trying to use a timer to use the arrow keys and i am using this
Code:
Private Declare Function GetKeyState Lib "user32" (ByVal keyCode As Integer) As Short
If GetKeyState(Keys.Up) Then
If pbxship.Top <= 77 Then
pbxship.Top += 10
Else
pbxship.Top -= 10
End If
ElseIf GetKeyState(Keys.Down) Then
If pbxship.Top >= 800 Then
PbxLazer.Top -= 10
Else
pbxship.Top += 10
End If
but this does not do anything like the keys are not pressed, does anyone know how to make it work or a different way to do this in a timer
thanks in advance
Re: using the keydown function in a timer
try this:
vb Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
Re: using the keydown function in a timer
it didnt do anything
i think it is because it does not have a value to determine if it is pressed or not, it just jets the key state. it needs a value like 0, 1 or true, false (these did not work). do you know what value they should be?
Re: using the keydown function in a timer
can you post the full code?
we should be able to see the problem
Re: using the keydown function in a timer
what do you mean by all the code? do you mean all the code on moving or just all the code
here is the moving code:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Long
Private Sub Tmrmove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tmrmove.Tick
'to move up and down
If GetAsyncKeyState(Keys.Up) = 1 Then
If pbxship.Top <= 77 Then
pbxship.Top += 10
Else
pbxship.Top -= 10
End If
ElseIf GetAsyncKeyState(Keys.Down) = 1 Then
If pbxship.Top >= 800 Then
PbxLazer.Top -= 10
Else
pbxship.Top += 10
End If
end sub
was that what you meant by all the code?
Re: using the keydown function in a timer
IT WORKS!!!!
i made a stupid mistake, i forgot to enable the timer:lol:
thanks for helping
Re: using the keydown function in a timer