?
Solved

Simulate Mouse Click

Posted on 2004-08-12
6
Medium Priority
?
2,464 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 668 total points
ID: 11783191
0
 
LVL 6

Assisted Solution

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

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

762 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