Solved

Simulate Mouse Click

Posted on 2004-08-12
6
2,460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 86

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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