|
-
Feb 14th, 2012, 07:55 PM
#1
Thread Starter
New Member
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
Last edited by samqweqwe3; Feb 16th, 2012 at 08:25 PM.
-
Feb 15th, 2012, 12:19 AM
#2
Re: using the keydown function in a timer
try this:
vb Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 15th, 2012, 05:38 AM
#3
Thread Starter
New Member
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?
Last edited by samqweqwe3; Feb 15th, 2012 at 05:56 AM.
-
Feb 15th, 2012, 06:00 AM
#4
Re: using the keydown function in a timer
can you post the full code?
we should be able to see the problem
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 15th, 2012, 06:04 AM
#5
Thread Starter
New Member
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?
Last edited by samqweqwe3; Feb 16th, 2012 at 08:24 PM.
-
Feb 15th, 2012, 06:29 AM
#6
Thread Starter
New Member
Re: using the keydown function in a timer
IT WORKS!!!!
i made a stupid mistake, i forgot to enable the timer
thanks for helping
-
Feb 15th, 2012, 06:39 AM
#7
Re: using the keydown function in a timer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|