Results 1 to 13 of 13

Thread: Why does my click and move funtion does not work?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Why does my click and move funtion does not work?

    PHP Code:
    Private Sub Button6_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button6.Click
            Button6_MouseClick
    (Button6, New MouseEventArgs(Windows.Forms.MouseButtons.Left21002000)) 
        
    End Sub

        
        
    Private Sub Button6_MouseClick(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgsHandles Button6.MouseClick
            
    If e.Button Windows.Forms.MouseButtons.Left AndAlso e.Clicks 2 Then ' if the e.Click has the value 2 -> click twice.
                '
    doubble left click
            
    End If
        
    End Sub 
    Why does this function not move the mouse to X100, Y200 and then doubble click?

    Has it something to do with user32.dll/user64.dll?

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Why does my click and move funtion does not work?

    Your code shows me that you are missing some fundamental things about the .NET language. This is how you can set the mouse cursor position:
    Code:
    '//to set the position of the cursor
    System.Windows.Forms.Cursor.Position = New Point(0, 100)
    
    And:
    Code:
    Private Sub Button1_MouseDoubleClick(ByVal sender As Object, _
                                         ByVal e As MouseEventArgs) _
                                         Handles Button1.MouseDoubleClick
        '//double mouse click
    End Sub
    
    If you want to send a double-click to a certain point then you need to use the SendMessage api.

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    ... because that's not how events work at all? I believe you want this in your Sub:

    Code:
    Windows.Forms.Cursor.Position = New Point(100, 200)
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    Threading.Thread.Sleep(60)
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    and this in your class:
    Code:
    Public Declare Auto Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Public Const MOUSEEVENTF_LEFTDOWN As Integer = 2
    Public Const MOUSEEVENTF_LEFTUP As Integer = 4

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: Why does my click and move funtion does not work?

    Quote Originally Posted by minitech View Post
    ... because that's not how events work at all? I believe you want this in your Sub:

    Code:
    Windows.Forms.Cursor.Position = New Point(100, 200)
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    Threading.Thread.Sleep(60)
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    and this in your class:
    Code:
    Public Declare Auto Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Public Const MOUSEEVENTF_LEFTDOWN As Integer = 2
    Public Const MOUSEEVENTF_LEFTUP As Integer = 4
    Thanks!
    Do you know how to make so the click waint on the progressbar?
    I have a webbrowser and the mouse will click on a webbsite's buttons to do something, but the webbsite may be slow sometimes. You know what i mean?

    1. Move mouse
    2. Click.
    3. Wait untill the website is 100% loaded(progressbar)
    4. move kouse
    5. click.

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    That's probably not easy. Although you can easily wait a set amount of time like so:
    Code:
    Threading.Thread.Sleep(secondsItWillTakeToLoad * 1000)
    , figuring out the progress bar value is another matter entirely. There's probably a way with window handles, I'll look for it now...

    Unless you're loading the page with the WebBrowser control? In that case, handle the DocumentCompleted event.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: Why does my click and move funtion does not work?

    Quote Originally Posted by minitech View Post
    That's probably not easy. Although you can easily wait a set amount of time like so:
    Code:
    Threading.Thread.Sleep(secondsItWillTakeToLoad * 1000)
    , figuring out the progress bar value is another matter entirely. There's probably a way with window handles, I'll look for it now...

    Unless you're loading the page with the WebBrowser control? In that case, handle the DocumentCompleted event.

    I don't know how to figure out when the progressbar is 100% loaded.
    Im loading the page with the webbrowser and using Internet explorer. What does the diffrent with WebBrowser control?

  7. #7
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    Handle its DocumentCompleted event.

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: Why does my click and move funtion does not work?

    Quote Originally Posted by minitech View Post
    Handle its DocumentCompleted event.
    http://msdn.microsoft.com/en-us/libr...completed.aspx

    PHP Code:

    Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler

    Private Sub Button6_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button6.Click 
            Windows
    .Forms.Cursor.Position = New Point(100200)
            
    mouse_event(MOUSEEVENTF_LEFTDOWN0000)
            
    mouse_event(MOUSEEVENTF_LEFTUP0000)
            
    Button1_WebBrowser(Button1, New ...something.........................)
            
    Windows.Forms.Cursor.Position = New Point(100200)
            
    mouse_event(MOUSEEVENTF_LEFTDOWN0000)
            
    mouse_event(MOUSEEVENTF_LEFTUP0000)
        
    End Sub 
    I don't have Visual Basic.net express 2008 right now, but im installing it now. Soon it's complete.
    I think the code will look like this?

  9. #9
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    No. It will look like this:

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles WebBrowser1.DocumentCompleted 
            Windows.Forms.Cursor.Position = New Point(100, 200)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
            Button1_WebBrowser(Button1, New ...something.........................)
            Windows.Forms.Cursor.Position = New Point(100, 200)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
        End Sub
    Change the red-highlighted names to the name of your WebBrowser control.

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: Why does my click and move funtion does not work?

    Quote Originally Posted by minitech View Post
    No. It will look like this:

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles WebBrowser1.DocumentCompleted 
            Windows.Forms.Cursor.Position = New Point(100, 200)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
            Button1_WebBrowser(Button1, New ...something.........................)
            Windows.Forms.Cursor.Position = New Point(100, 200)
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
        End Sub
    Change the red-highlighted names to the name of your WebBrowser control.
    Hmmm wait on the progressbar seems very hard, so I think i going to skip that and just use this code insted.
    PHP Code:
    Threading.Thread.Sleep(60
    Can it not count at seconds? Not just miliseconds?

    1.Move mouse
    2. Click
    3. Wait 5 seconds.
    4. move mouse
    5. click
    Last edited by Heavy.Is.Happy; Jun 27th, 2011 at 03:34 PM.

  11. #11
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    Does it really matter? You can count out milliseconds just by adding 3 zeroes to the seconds, not that hard.

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    53

    Re: Why does my click and move funtion does not work?

    Quote Originally Posted by minitech View Post
    Does it really matter? You can count out milliseconds just by adding 3 zeroes to the seconds, not that hard.

    Can i not do this.

    PHP Code:
    Private Sub WebBrowser1_ProgressChanged(By*Val sender As ObjectByVal e As System.Windows.Forms.WebBrowse*rProgressChangedEventArgsHandles WebBrowser1.ProgressChanged 

    ProgressBar1
    .Maximum e.MaximumProgress
    ProgressBar1
    .Value e.CurrentProgress 

    End Sub 
    This makes the progressbar work with the webbrowser.

    And this make the progressbar get a variable value.
    http://www.java2s.com/Tutorial/VB/02...ssBarvalue.htm
    Last edited by Heavy.Is.Happy; Jun 27th, 2011 at 04:33 PM.

  13. #13
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Why does my click and move funtion does not work?

    Okay - you can do that too. But why use the progress bar when you can just handle an event?

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