|
-
Jun 16th, 2006, 11:21 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Keys
Right now i'm using
If keycode = vbkeyright then
me.right = me.right + 100
endif
If keycode = vbkeyup then
me.top = me.top - 100
endif
how do i make it so i can press them both at the same time so i can have both effects at the same time?
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful 
-
Jun 16th, 2006, 12:23 PM
#2
Re: Keys
Well, you can't check 2 keys at once. Here is an alternative I found somewhere and modified it a little.
This code is not very good, 'cause it needs a timer. But it works. 
First, in Key_Up/Down event check which keys are pressed, then inside the timer move the form depending on those keys.
VB Code:
Option Explicit
Dim bUpPressed As Boolean
Dim bDownPressed As Boolean
Dim bLeftPressed As Boolean
Dim bRightPressed As Boolean
'=============================================================
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
bUpPressed = True
bDownPressed = False
Case vbKeyDown
bDownPressed = True
bUpPressed = False
Case vbKeyLeft
bLeftPressed = True
bRightPressed = False
Case vbKeyRight
bRightPressed = True
bLeftPressed = False
End Select
End Sub
'=============================================================
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
bUpPressed = False
Case vbKeyDown
bDownPressed = False
Case vbKeyLeft
bLeftPressed = False
Case vbKeyRight
bRightPressed = False
End Select
End Sub
'=============================================================
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
'=============================================================
Private Sub Timer1_Timer()
If bUpPressed = True Then
Me.Top = Me.Top - 50
ElseIf bDownPressed = True Then
Me.Top = Me.Top + 50
End If
'
If bLeftPressed = True Then
Me.Left = Me.Left - 50
ElseIf bRightPressed = True Then
Me.Left = Me.Left + 50
End If
End Sub
-
Jun 16th, 2006, 01:27 PM
#3
Addicted Member
Re: Keys
Hi lilwupster,
This code involves a couple API calls, but it's a little more straight forward.
It should also do what you want.
Add a timer control first
VB Code:
'in the declare section
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
'check if window has focus
'otherwise window will move even when another program has focus
If GetActiveWindow() <> Me.hWnd Then Exit Sub
If GetAsyncKeyState(vbKeyUp) Then Me.Top = Me.Top - 15
If GetAsyncKeyState(vbKeyDown) Then Me.Top = Me.Top + 15
If GetAsyncKeyState(vbKeyLeft) Then Me.Left = Me.Left - 15
If GetAsyncKeyState(vbKeyRight) Then Me.Left = Me.Left + 15
End Sub
Hi iPrank, I swear I'm not stalking you. thanks for the rate.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
-
Jun 16th, 2006, 03:19 PM
#4
Thread Starter
Addicted Member
Re: Keys
thank you, they both work very well
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful 
-
Jun 16th, 2006, 05:14 PM
#5
Addicted Member
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
-
Jun 16th, 2006, 05:18 PM
#6
Re: Keys
DirectInput would have also done it.
-
Jun 16th, 2006, 09:48 PM
#7
Re: Keys
 Originally Posted by Keith_VB6
Hi iPrank, I swear I'm not stalking you. thanks for the rate.
Don't worry. 
iSpy on people everyday.
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
|