-
May 3rd, 2011, 09:48 PM
#1
Thread Starter
New Member
keypress inside a timer? [vb6]
what code would i need to get a keypress in side of a timer?
-
May 4th, 2011, 08:26 AM
#2
Re: keypress inside a timer? [vb6]
Do you mind explaining a bit more ?
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
May 4th, 2011, 11:04 PM
#3
Thread Starter
New Member
Re: keypress inside a timer? [vb6]
i'm trying to program a platfrom game for my major project, which i have to code in vb, i've programmed a platfrom game before in C, i'm using a timer to emulate the sequential programming the i am use to in C, so i don't have to change code much , but i'm having trouble with what code i need to get the "keypress" function to work in the the timer so i can get my character to move.
i hope this makes sence :P
-
May 5th, 2011, 05:01 AM
#4
Re: keypress inside a timer? [vb6]
Maybe GetAsyncKeyState API would help you.
Example:
vb Code:
Option Explicit
'~~~ API
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'~~~ Start the Timer
Private Sub Form_Load()
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
'~~~ We are trying to detect the key being pressed and do whatever we want
Private Sub Timer1_Timer()
'~~~ Move up
If GetAsyncKeyState(vbKeyUp) Then
Command1.Top = Command1.Top - 10
End If
'~~~ Move down
If GetAsyncKeyState(vbKeyDown) Then
Command1.Top = Command1.Top + 10
End If
'~~~ Move left
If GetAsyncKeyState(vbKeyLeft) Then
Command1.Left = Command1.Left - 10
End If
'~~~ Move right
If GetAsyncKeyState(vbKeyRight) Then
Command1.Left = Command1.Left + 10
End If
End Sub
Try pressing both the right & down key. You'll see that it moves in a lean way to right.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
May 8th, 2011, 06:22 PM
#5
Thread Starter
New Member
Re: keypress inside a timer? [vb6]
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
|