We help IT Professionals succeed at work.
Get Started

Time interval between lines of code

HyMaX_2003 asked
Last Modified: 2010-05-02
Hello! I got a code that makes a CTRL + Mouse Click in a specific place of your screen. You define these places to click by typing in a

textbox something like "MouseClick 100, 100" (X and Y coordinates). You can also make a sequence of clicks by typing a command like

that in each line. But there's a problem in that, it's TOO FAST. I need to put intervals between these Mouse Click commands, but I

have no idea how to make it. The code is the following:

Option Explicit

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, _
ByVal y As Long) As Long

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo

As Long)

Private Const VK_CONTROL = &H11
Private Const KEYEVENTF_KEYUP = &H2


Private tmpData As String

Public Sub MouseClick(x As Long, y As Long)
SetCursorPos x, y
keybd_event VK_CONTROL, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN, x, y, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, x, y, 0, 0
End Sub

Private Sub Timer1_Timer()

tmpData = Text1.Text
Dim arrTmp() As String, i As Long, arrVal() As String

If tmpData <> "" Then
arrTmp = Split(tmpData, vbNewLine)
For i = 0 To UBound(arrTmp)
If arrTmp(i) <> "" Then
arrVal = Split(arrTmp(i), " ")
If UBound(arrVal) = 2 Then
MouseClick CLng(Left$(arrVal(1), Len(arrVal(1)) - 1)), CLng(arrVal(2))
MsgBox arrTmp(i), vbCritical, "Error"
End If
End If
Next i
End If

End Sub

I need something like the following, to appear in my textbox:

MouseClick 100, 100
Wait 1 second
MouseClick 100, 100
Wait 0,5 second

Can someone help me? Please...
Watch Question
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE