It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

I need help with the KeyUp and KeyDown

Moderator: dafunkymunky

I need help with the KeyUp and KeyDown

Postby anonymoushidden on Fri Feb 25, 2011 8:27 am

'[GENERAL DECLARATIONS]
Dim moveUp, moveDown, moveLeft, moveRight As Boolean

Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)


If KeyCode = vbKeyUp Then
moveUp = True
ElseIf KeyCode = vbKeyDown Then
moveDown = True
ElseIf KeyCode = vbKeyLeft Then
moveLeft = True
ElseIf KeyCode = vbKeyRight Then
moveRight = True
End If

End Sub

Private Sub Picture1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
moveUp = False
ElseIf KeyCode = vbKeyDown Then
moveDown = False
ElseIf KeyCode = vbKeyLeft Then
moveLeft = False
ElseIf KeyCode = vbKeyRight Then
moveRight = False
End If

End Sub


'But my problem is how am I gonna make another Private Sub which utilizes both KeyUp and KeyDown. It would loke like this:

If moveUp = true then
Image5.Top = Image5.Top - 150

How will I make another private sub? And what would it's name be?
anonymoushidden
 
Posts: 1
Joined: Fri Feb 25, 2011 8:20 am

Re: I need help with the KeyUp and KeyDown

Postby sanjon on Thu Mar 10, 2011 10:31 am

Can't you just do this:

Dim moveUp, moveDown, moveLeft, moveRight As Boolean
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
moveUp = True
ElseIf KeyCode = vbKeyDown Then
moveDown = True
ElseIf KeyCode = vbKeyLeft Then
moveLeft = True
ElseIf KeyCode = vbKeyRight Then
moveRight = True
End If
KeyUpDown()
End Sub

Private Sub Picture1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
moveUp = False
ElseIf KeyCode = vbKeyDown Then
moveDown = False
ElseIf KeyCode = vbKeyLeft Then
moveLeft = False
ElseIf KeyCode = vbKeyRight Then
moveRight = False
End If
KeyUpDown()
End Sub

Private Sub KeyUpDown()
If moveUp = true then
moveUp = false
Image5.Top = Image5.Top - 150
End If
End Sub

Give it a try and let me know...
sanjon
 
Posts: 40
Joined: Sun Dec 05, 2010 6:20 pm


Who is online

Users browsing this forum: No registered users and 1 guest