Solved

Simulate Mouse Click

Posted on 2004-08-12
6
2,459 Views
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?
0
Comment
Question by:thunderchicken
6 Comments
 
LVL 6

Accepted Solution

by:
mmusante earned 167 total points
ID: 11783191
0
 
LVL 6

Assisted Solution

by:bkthompson2112
bkthompson2112 earned 167 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"

bkt
0
 
LVL 11

Author Comment

by:thunderchicken
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Author Comment

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

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 166 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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

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
0
 
LVL 11

Author Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

830 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