• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2472
  • Last Modified:

Simulate Mouse Click

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
thunderchicken
Asked:
thunderchicken
3 Solutions
 
bkthompson2112Commented:
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
 
thunderchickenAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
thunderchickenAuthor Commented:
But this really wont be on a form, since it will be using another application, not a VB App
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
thunderchickenAuthor Commented:
Found code on a site, thanks, will split for everyone's input
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now