Tutorial: How to make a basic auto clicking program
This tutorial will teach the reader how to make a basic clicking program that will click on coordinates set by the user every 2 seconds.
Original Author: tazrockon
Code
Before you begin this tutorial there are some things I expect you to know. The first thing you need to do is open up Visual Basic and start a Standard Here's how the program is going to work when we are finished. When the form Now the light reading is over and we are ready to get down to the code. Make Declare Function GetCursorPos& Lib "user32" Line1 : This is needed to tell the computer the program Go back to your form and add a timer. Set Enabled to True and the Interval Dim pos Line1 : This sets pos as a variable. If you have done everything correctly you should now be able to run the program. Timer1.Enabled = False Line1 : Disables Timer1 so that it will stop reading Go back to the form and double click on the button that reads "Unlock". Timer1.Enabled = True Line1 : Re-enables Timer1 so that it will start showing Now run the program. Test out clicking the Lock and Unlock buttons. Have you We have set up the GUI, gotten the mouse's coordinates, and made Lock and Unlock Declare Function SetCursorPos Lib "user32" Line1 : This is needed to tell the computer what to use Now we need to turn these API's into actions that are program can do. First Sub MouseMove(xP As Long, yP As Long) Line1 : This creates the MouseMove Sub and sets the variable We have the code in the module to make our mouse move, but how do we incorporate Dim xP As Long Line1 : Sets the variable xP as Long Go back to your form. Double click on the button on the right side of the form Timer2.Enabled = True Line1 : This enables (turns on) Timer2 that has the MouseMove Now go back to your form and double click on the button that reads "End". Timer2.Enabled = False Line1 : This disables Timer2 and will make the program Now run the program. Position your mouse somewhere on the screen and lock its' Sub LeftClick(xP As Long, yP As Long) Line1 : This creates the LeftClick sub and sets the variables Go back to the form and look at the Timer2 code. Below the MouseMove line we LeftClick (xP), (yP) Line1 : Uses the LeftClick sub that we put in our module We should now have a fully functional automatic clicking program that will *Make a program that clicks on 2 or more points.
By Tazrockon
You should have some experience with programming in Visual Basic and you should
at least have some basic knowledge of how to use Windows API in your programs.
I also expect you to be able to use forms, modules, and the standard Visual
Basic objects. Using this knowledge that already exists in your head I will
now attempt to teach you how to make a simple auto clicker that will repeatedly
click a certain coordinate on the screen every two seconds until told to stop.
EXE. On your form place two text boxes, two labels, and four command buttons.
Position the two text boxes side by side with some space in between in the middle
of the left side of the form. Above each text box put the two labels. Below
the two text boxes put two command buttons. Now, on the right side of the form
put the other two text boxes one above the other. In the label above the first
text box type in "X Pos:" (without the " 's). In the other label
type "Y Pos:". Clear out the text of the two text boxes and make the
first command button below them say "Lock" and the other "Unlock".
Now in the first command button on the right side of the form type in "Begin"
and in the one below it type "End". Now your GUI is pretty much finished.
loads, the first text box will contain the user's mouse's X coordinate and the
second will contain the user's Y coordinate as they move their mouse around
the screen. The first command button under the mouse position boxes that reads
"Lock" will be used to lock the users current mouse coordinates in
the text boxes so the user can move their mouse around without the text box's
numbers changing. The second command button which reads "Unlock" will
be used to unlock the current coordinates in the text boxes so that the user
can see their mouse's coordinates once again as they move their mouse across
the screen. The first command button on the right that reads "Begin"
will make the program start clicking the coordinates locked by the user and
the "End" button below it will make the program stop clicking.
a new Module and in it add the lines:
(lpPoint As PointAPI)
Type PointAPI
X As Long
Y As Long
End Type
wants to get the cursor position.
Line2 : This starts PointAPI.
Line3 : Sets the X coordinate variable as Long.
Line4 : Sets the Y coordinate variable as Long.
Line5 : This ends PointAPI.
to 10. Double click on the timer to get to the code window so you can make the
timer do something. In the timer sub type:
Dim pt As PointAPI
pos = GetCursorPos(pt)
Text1.Text = pt.X
Text2.Text = pt.Y
Line2 : This sets the variable pt to the PointAPI used in the module.
Line3 : Sets pos equal to GetCursorPos(pt). Basicly it gets the mouse coordinates
from the PointAPI.
Line4 : Makes Text1 read out the current X position of the mouse.
Line5 : Makes Text2 read out the current Y position of the mouse.
When it starts up it should tell the current position of your mouse as you move
it across the screen. Try moving your mouse to the very left bottom corner of
your computer screen and see what it says the coordinates are. Now we can add
the ability to Lock and Unlock coordinates. You will probably be suprised at
how easy this is to do. Go back to your form and double click on the button
that reads "Lock". In the command sub type:
out the mouse coordinates.
In this command sub in the code window type:
the current coords again.
found something bad about these buttons? Chances are you have. You can not lock
the coords of anywhere except where the Lock button is. This can easilly be
fixed. Go back to your form and click on the Lock button once. Now change the
caption from "Lock" to "&Lock". Notice how the button
now reads Lock. This means that when you run your program if you press Alt and
L on your keyboard your program will act as if you pressed the Lock button.
This will enable you to lock coordinates anywhere on your monitor.
buttons. What are we going to do now? We are going to make the code that will
make our program actually click on the coordinates we lock. This is the hardest
part of the tutorial, but if you have made it this far alright and you have
gotten the code to get the cursor position to work, then you should be able
to achieve our new goal. Open up the module and add the following beneath End
Type of our Point API:
(ByVal X As Long, ByVal Y As Long) As Long
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)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
to set the cursor position.
Line2 : Gets different mouse events from the computer.
Line3 : Makes the mouse event left down public so we can use it in the rest
of our module.
Line4 : Makes the mouse event left up public so we can use it in the rest of
our module.
we will make the MouseMove action that we will use to, you got it, move the
mouse. Under the last line of API that we typed add the following code:
Dim move
move = SetCursorPos(xP, yP)
End Sub
xP and yP yo Long.
Line2 : Sets the variable move.
Line3 : Sets move equal to the API SetCursorPos in (xP,yP),
Line4 : Ends the Sub.
this into our form? Now the magic will begin. Go back to your form and add a
second timer. Set Enabled to False and make the Interval 2000 (every two seconds).
Double click on it and add this code:
Dim yP As Long
xP = Text1.Text
yP = Text2.Text
MouseMove (xP), (yP)
Line2 : Sets the variable yP as Long
Line3 : Makes xP equal the X position that's in the first text box
Line4 : Makes yP equal the Y position that's in the second text box
Line5 : Uses the MouseMove sub that we put in our module to move the mouse to
the locked coordinates (xP and yP)
that reads "Begin". Here we will put in the code that enables our
second timer. Type in this code:
procedure in it.
Here we will put the code that disables the second timer, which will make the
program stop trying to move the mouse to the locked coordinates.
stop moving the mouse.
position. Click the begin button and watch your mouse move to the coordinates
you locked. Now quickly move your mouse over the Endd button and click on it.
This should make your program stop moving the mouse. All we have left to do
is make the program click on the coordinate. Go back to the module and add the
following code below our MouseMove sub:
mouse_event MOUSEEVENTF_LEFTDOWN, xP, yP, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, xP, yP, 0, 0
End Sub
xP and yP as Long.
Line2 : Tells our program to push down the left mouse button on the coordinates.
Line3 : Tells our program to let up the left mouse button on the coordinates.
Line4 : Ends the LeftClick sub.
need to add the code that will pull the LeftClick procedure from the module.
This is very easy. Add this code to the Timer2 sub:
to left click the coordinates.
click on given coordinates every two seconds until told to stop. Some things
to try are:
*Use a slider to allow the user to change the clicking interval.
*Make a mouse macro that will run Paint by clicking on Start, moving the mouse
up to Programs, move the mouse up to Accessories, and clicking on Paint.
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.