Improve company productivity with a Business Account.Sign Up


Simulate Mouse Click

Posted on 2004-08-12
Medium Priority
Last Modified: 2008-02-01
Say I have a game where I want to click on the mouse button every second at a certain location.  Is there a script to do this, so i can sit back and watch?

Say for example, a slot machine?
Question by:thunderchicken

Accepted Solution

mmusante earned 668 total points
ID: 11783191

Assisted Solution

bkthompson2112 earned 668 total points
ID: 11783207
Hi thunderchicken,

You can call the button's click event:  Command1_Click
It's just a function, call it like any other function.

Put it in a loop.  you could also use the sleep api/timing loop to adjust how often the button gets "clicked"

LVL 11

Author Comment

ID: 11783240
That's what I'm thinking, something like that.  I'll be running this through remote computer, and wanting to tab out and let it run on that computer, and I can watch the progress for any errors.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

LVL 11

Author Comment

ID: 11783247
But this really wont be on a form, since it will be using another application, not a VB App
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 664 total points
ID: 11783274
Create a new project and add a timer control:

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 Sub Form_Load()
    Timer1.Interval = 1000 ' one second
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

Private Sub Timer1_Timer()
    MouseClick 100, 100 ' change this to the coordinates you need
End Sub
LVL 11

Author Comment

ID: 11783279
Found code on a site, thanks, will split for everyone's input

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As a person who answers a lot of questions, I often see code that could be simplified, made easier to read, and perhaps most importantly made easier to maintain if the code was modified to use the Select Case statement. This article explains how to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question