code to click, move, double click, mouse?

is there a way to move a mouse to a certain point on the screen and click/double click it there through code with VB6?
also, how can i get the coordinates of the mouse at a certain point?
djiangrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Create a new project and add a Label and a Timer.  The code below will show you the current position of the cursor.  To simulate a mouse click at some point on the screen just use the MouseClick() function passing in the X,Y coordinates of the point you want clicked on.  To simulate a double click just call MouseClick() twice in a row with the same coordinates.

Regards,

Idle_Mind


Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Private Sub Form_Load()
    Timer1.Interval = 50
End Sub

Private Sub Timer1_Timer()
    Dim z As POINTAPI
    GetCursorPos z
    Label1.Caption = z.x & ", " & z.y
End Sub

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
djiangrAuthor Commented:
would this code work outside the form?  say i wnated to make it click something on the desktop, would that work?

i want tto make somethign that will move the mouse to certain points on the screen and click it

will it work if the program is minimized?

thanksss.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
>> would this code work outside the form?  say i wnated to make it click something on the desktop, would that work?

Yes, it will work anywhere on the screen.

>> i want tto make somethign that will move the mouse to certain points on the screen and click it

The MouseClick() sub will move the cursor and then click on the point passed in.

>> will it work if the program is minimized?

To make it work while minimized you would need to either use a timer or possibly register a HotKey to make the code run.  Explain a little further how you want your app to work and I can suggest a more concrete solution.

~IM
0
djiangrAuthor Commented:
thanks,
i wanted to make a thing where you can set at a certain time when to move the mouse click where, etc.
for example, it could shut down the computer at a certain time or something like that...(i know there are programs to do this, but just an example)

0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Sure, that's possible via the use of the built in Timer control.  You just poll the current time with the timer control and when the target time has been reached, call the MouseClick() sub with the desire coordinates.

~IM
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.