Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Move the mouse from VB

Move the mouse from VB

Move the mouse from VB


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

Thanks a lot!

RE: Move the mouse from VB

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
    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!

RE: Move the mouse from VB

Again, i solved the problem before someone replys me.

In a module, declare:

Public 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)
Public Declare Function SetCursorPos Lib "user32" (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 "user32" (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.!

RE: Move the mouse from VB

Good work, and thanks for posting the solution for the rest of us!

RE: Move the mouse from VB

'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

RE: Move the mouse from VB


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close