[RESOLVED] Left Click, Sleep, Move Mouse, Sleep, etc...
I know this is probably basic but I'm having trouble figuring it out even with excessive amounts of googling...
This is the code I am working with...
HTML Code:
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Me.Cursor.Position = New Point(535, 195)
Sleep(500)
mouse_event(MOUSEEVENTF_LEFTDOWN, 335, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 335, 195, 0, 0)
Sleep(5000)
Me.Cursor.Position = New Point(390, 195)
Sleep(500)
mouse_event(MOUSEEVENTF_LEFTDOWN, 390, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 390, 195, 0, 0)
End Sub
The goal is to move cursor over a button in a webbrowser and click it, wait 5 seconds, move cursor over another button, click that button and so on...
Everything is working, the cursor moves appropriately, the mouse clicks fine, but it doesn't do them sequentially. It does the following...
- Moves mouse to first location (but doesn't click)
- Waits about 7 seconds (not sure why, I would think it would be either 5.5 or 11 seconds...)
- Moves to second mouse location and clicks mouse button twice in a row fast
This is for a program just for me, this is the way I need to perform this, I could program it easily in autoit but would like to do it inside the vb code like this somehow.
What am I doing wrong???
Thanks for any help or points in the right direction!
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
Don't use Sleep. If you want a pause between actions then use a Timer and perform your actions on the Tick event. If you need to change the interval between actions then Stop the Timer, change the Interval and then Start the Timer again.
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
I'm confused about how the timer control works... Please help me...
Assume these are the actions that I want to do with a pause in between them each...
Move mouse to 1st position
Code:
Me.Cursor.Position = New Point(390, 195)
Left mouse click
Code:
mouse_event(MOUSEEVENTF_LEFTDOWN, 390, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 390, 195, 0, 0)
Move mouse to 2nd position
Code:
Me.Cursor.Position = New Point(623, 195)
Left mouse click over that position
Code:
mouse_event(MOUSEEVENTF_LEFTDOWN, 623, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 623, 195, 0, 0)
I am very new at vb, this is all I know to do so far, could you please help me fill in the gaps. I would greatly appreciate it!
I put
HTML Code:
Timer1.Interval = 500
Timer1.Enabled = True
in the form load
then, what would I put in this...
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
'what goes here?
End Sub
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
500 needs to be 5000 to get a 5 second pause. 500 is only half a second.
What goes into the tick event handler is pretty much everything. You will need a form level variable of type integer. Start that variable at 0. In the tick event handler you would have something like this:
Code:
<your variable> += 1 'Add one to it.
If <your variable> = 1 Then
'Do the first move and click.
ElseIf <your variable> = 2 Then
'Do the second move and click.
Else
'Do the third move and click....and stop the timer.
End If
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
Ok, thanks guys!
This is what I exactly what I needed, here is some code to leave for future searchers...
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Advance tick variable by 1
tickx = tickx + 1
'Do first action
If tickx = 2 Then
Me.Cursor.Position = New Point(337, 195)
'Second Action
ElseIf tickx = 3 Then
mouse_event(MOUSEEVENTF_LEFTDOWN, 390, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 390, 195, 0, 0)
'Third
ElseIf tickx = 4 Then
Me.Cursor.Position = New Point(398, 195)
'And last action
ElseIf tickx = 5 Then
mouse_event(MOUSEEVENTF_LEFTDOWN, 390, 195, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 390, 195, 0, 0)
End If
End Sub
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
RESOLVED, not sure if there is a button to mark that or not...
Re: Left Click, Sleep, Move Mouse, Sleep, etc...
Quote:
Originally Posted by
telepunk
RESOLVED, not sure if there is a button to mark that or not...
Use the Thread Tools menu.