Why does my click and move funtion does not work?
PHP Code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Button6_MouseClick(Button6, New MouseEventArgs(Windows.Forms.MouseButtons.Left, 2, 100, 200, 0))
End Sub
Private Sub Button6_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 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?
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.
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
Re: Why does my click and move funtion does not work?
Quote:
Originally Posted by
minitech
... 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.
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.
Re: Why does my click and move funtion does not work?
Quote:
Originally Posted by
minitech
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?
Re: Why does my click and move funtion does not work?
Handle its DocumentCompleted event.
Re: Why does my click and move funtion does not work?
Quote:
Originally Posted by
minitech
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.Object, ByVal e As System.EventArgs) Handles Button6.Click
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
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?
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.
Re: Why does my click and move funtion does not work?
Quote:
Originally Posted by
minitech
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
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.
Re: Why does my click and move funtion does not work?
Quote:
Originally Posted by
minitech
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 Object, ByVal e As System.Windows.Forms.WebBrowse*rProgressChangedEventArgs) Handles 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
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?