Visual Basic Random Move / Click

Currently I have a program that will click in a specific coordinate. What I want to know is if it's possible for vb to randomly move / click in a spot. This is what I have so far, and it works with moving to the (Area). The total area of the object is TopLeft: 115, 734 and BottomRight: 153,763. So if possible can I tell it to move and click anywere from 115,734 & 153, 763. Thanks.

 Dim Area = (New Point(Val(135), Val(747)))

AppActive("Current App Focus Needed I guess")

MouseMoveTo(Area)

Open in new window

LVL 1
Jack_JonesAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You can do something like this:

    MoveMouseToArea(New Point(115, 734), New Point(153, 763))

Using this Sub:
Private Sub MoveMouseToArea(ByVal TopLeft As Point, ByVal BottomRight As Point)
        Static R As New Random
        MoveMouseTo(New Point(R.Next(TopLeft.X, BottomRight.X + 1), R.Next(TopLeft.Y, BottomRight.Y+1))
    End Sub

Open in new window

0
 
MlandaTCommented:
Have look at these, you can take out the timer stuff, or at least easily pick out how they are doing the mouseclick (the basic concept is they send window messages indicatingg various facts about the mouse click):

http://www.codeproject.com/KB/system/Auto_Clicker.aspx
http://www.codeproject.com/KB/cs/Auto_Clicker_Bar.aspx

http://www.dreamincode.net/forums/topic/67915-helpauto-clicker-vb2008/
0
 
Jack_JonesAuthor Commented:
So I could do the following then? Was hopeing to make it where I could just say here is a list of x, y coordinates use these at random times.

 Dim Area = (New Point(Val(135), Val(747)))
 Dim Area2 = (New Point(Val(136), Val(748)))
 Dim A As Integer

AppActive("Current App Focus Needed I guess")

If A = 0 Then
            MoveMouseTo(Area)
            A = A + 1
           ' insert mouse click command
        Else
            MoveMouseTo(Area2)
            A = 0
           ' insert mouse click command
        End If

Open in new window

0
 
Jack_JonesAuthor Commented:
Awesome man, thanks again your on fire.
0
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.

All Courses

From novice to tech pro — start learning today.