Results 1 to 2 of 2

Thread: Keydown Doesn't Work With WebBrowser Control on Form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    I am making a game where there is an animation, but now the hero won't walk! (the hero is not the animation) How can I make him move while having the webbrowser control on my form?(i'm using the webbrowser control to load an animated gif)

    Thanks A Bunch!
    Steve

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try using the GetAsyncKeyState API with a Timer Control, eg.
    Code:
    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 = 100
    End Sub
    
    Private Sub Timer1_Timer()
        'Only Move if your Form is Active
        If GetActiveWindow <> hWnd Then Exit Sub
        If GetAsyncKeyState(vbKeyLeft) Then
            Caption = "Moving Left"
            WebBrowser1.Left = WebBrowser1.Left - 100
        ElseIf GetAsyncKeyState(vbKeyRight) Then
            Caption = "Moving Right"
            WebBrowser1.Left = WebBrowser1.Left + 100
        End If
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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