Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move the mouse from VB

Status
Not open for further replies.

efighettib

Structural
Jan 13, 2004
26
CL
Hello

I need ideas to move the mouse to specific locations of the screen (not only my programm), and click over there.

Thanks a lot!

 
Replies continue below

Recommended for you

After a long wait, I solved this problem on my own.

In a module, you have to declare

Public Declare Function GetTickCount Lib "kernel32" () As Long

Public Sub wait(ByVal dblMilliseconds As Double)
Dim dblStart As Double
Dim dblEnd As Double
Dim dblTickCount As Double

dblTickCount = GetTickCount()
dblStart = GetTickCount()
dblEnd = GetTickCount + dblMilliseconds

Do
DoEvents
dblTickCount = GetTickCount()
Loop Until dblTickCount > dblEnd Or dblTickCount < dblStart


End Sub



all what you kave to do now is to call wait(num), when num in the amount of miliseconds that the program waits to continue in the next line.

Thanks to me!
 
Again, i solved the problem before someone replys me.

In a module, declare:

Public Declare Sub mouse_event Lib &quot;user32&quot; (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetCursorPos Lib &quot;user32&quot; (ByVal X As Long, ByVal Y As Long) As Long
Public Const mouse_eventC = &H2 ' Event contains mouse event record
Public Const MOUSE_MOVED = &H1
Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Public Declare Function GetCursorPos Lib &quot;user32&quot; (lpPoint As POINTAPI) As Long

Public Type POINTAPI
X As Long
Y As Long
End Type

Public Function GetX() As Long
Dim n As POINTAPI
GetCursorPos n
GetX = n.X
End Function

Public Function GetY() As Long
Dim n As POINTAPI
GetCursorPos n
GetY = n.Y
End Function

-------------------------------------------

Now to move the mouse to a certain location, and clic there, you have to call in this way

SetCursorPos X, Y
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
---------------------------------------------
Thaks to me.!
 
Good work, and thanks for posting the solution for the rest of us!
 
'Add attachment(s) - ALL .PDF files within app.path directory - destroy file after adding as attachment and copying to fileserver
Dim g_AttPass% '// Attacment Index
Dim New_File3$ '// File string
g_AttPass = -1
Do while dir(app.path & "\*.PDF") > ""
New_File3 = Dir(App.Path & "\*.PDF")
FileCopy App.Path & "\" & New_File3, "\\Fileserver1\FILESER1_E\web solidworks dwg_pdf\" & New_File3
Kill App.Path & "\" & New_File3
g_AttPass = g_AttPass + 1 'Increment attachment index
MAPIMessages1.AttachmentIndex = MAPIMessages1.AttachmentCount
MAPIMessages1.AttachmentPosition = g_AttPass
MAPIMessages1.AttachmentPathName = "\\Fileserver1\FILESER1_E\web solidworks dwg_pdf\" & New_File3
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top