Results 1 to 5 of 5

Thread: keypress inside a timer? [vb6]

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2010
    Location
    Australia
    Posts
    7

    Question keypress inside a timer? [vb6]

    what code would i need to get a keypress in side of a timer?

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2010
    Location
    Australia
    Posts
    7

    Question 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

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: keypress inside a timer? [vb6]

    Maybe GetAsyncKeyState API would help you.

    Example:
    vb Code:
    1. Option Explicit
    2.  
    3. '~~~ API
    4. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    5.  
    6. '~~~ Start the Timer
    7. Private Sub Form_Load()
    8.     Timer1.Interval = 1
    9.     Timer1.Enabled = True
    10. End Sub
    11.  
    12. '~~~ We are trying to detect the key being pressed and do whatever we want
    13. Private Sub Timer1_Timer()
    14.     '~~~ Move up
    15.     If GetAsyncKeyState(vbKeyUp) Then
    16.       Command1.Top = Command1.Top - 10
    17.     End If
    18.    
    19.     '~~~ Move down
    20.     If GetAsyncKeyState(vbKeyDown) Then
    21.       Command1.Top = Command1.Top + 10
    22.     End If
    23.    
    24.     '~~~ Move left
    25.     If GetAsyncKeyState(vbKeyLeft) Then
    26.       Command1.Left = Command1.Left - 10
    27.     End If
    28.    
    29.     '~~~ Move right
    30.     If GetAsyncKeyState(vbKeyRight) Then
    31.       Command1.Left = Command1.Left + 10
    32.     End If
    33. 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,...

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2010
    Location
    Australia
    Posts
    7

    Re: keypress inside a timer? [vb6]

    thank you it works.

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
  •  



Click Here to Expand Forum to Full Width