Page 1 of 1

How to make a Mouse Macro

Posted: Sat Mar 12, 2011 6:44 am
by Usman55
Hello Everyone,

I haven't wrote any tutorial lately but here is one. This is a tutorial about how to make a mouse macro. In this application, you simply enter the co-ordinates to move the mouse to and also it's speed. Just follow the tutorial and the results will be amazing. You can even use this technique to make a mouse macro in which you can enter multiple values using a timer. I found this project today when I was cleaning my computer. I got a PM by Scottie and he gave me the link to the site from whom I got this project a while ago. He gave a simple tutorial and I followed it and made an application out of it. Now I found it today and didn't knew who made it so here are the credits:

Article: http://www.sythe.org/showthread.php?t=160151
Author: slashshot007

---------------------------------------------------------------------------

First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Mouse Macro and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.


First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Mouse Macro. Change it's StartPosition property to CenterScreen. Change it's MaximizeBox and MinimizeBox property to False.


Now add the following things to the form:

(1)_ 4 Labels. Change Label1's Text property to anything as long as it shows you the thing to do. Change Label2's Text property to X, Label3's to Y and Label4's to S or Speed.

(2)_ 3 TextBoxes. Place the first one below X, second one below Y and third one below S.

(3)_ 1 Button. Change it's Text property to "Move".


Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.

Type the following code after the Public Class Form1:
Code: Select all
Sub movemousesmooth(ByVal x As Integer, ByVal y As Integer, ByVal speed As Integer)
        Dim currentlocationx As Integer, currentlocationy As Integer, random As Integer
        currentlocationx = Windows.Forms.Cursor.Position.X
        currentlocationy = Windows.Forms.Cursor.Position.Y
        Do Until currentlocationx = x And currentlocationy = y
            If speed = 1 Then
                random = 1
            Else
                random = CStr(Int(Rnd() * speed))
                If random = 0 Then random = CStr(Int(Rnd() * speed))
            End If
            If currentlocationx > x Then currentlocationx = currentlocationx - random
            If currentlocationx < x Then currentlocationx = currentlocationx + random
            If currentlocationy > y Then currentlocationy = currentlocationy - random
            If currentlocationy < y Then currentlocationy = currentlocationy + random
            Windows.Forms.Cursor.Position = New Point(currentlocationx, currentlocationy)
            Wait(0.5)
        Loop
    End Sub

    Public Declare Function timeGetTime Lib "winmm.dll" () As Long

    Public Sub Wait(ByVal TimeOut As Long)
        Dim CurrentTime As Long
        CurrentTime = timeGetTime()
        Do
            System.Windows.Forms.Application.DoEvents()
        Loop While CurrentTime + TimeOut > timeGetTime()
    End Sub
Add the following code to Button1 by double-clicking it:
Code: Select all
movemousesmooth(TextBox1.Text, TextBox2.Text, TextBox3.text)
This code "movemousesmooth" is the thing which will do the thing, if that makes sense lol.


---------------------------------------------------------------------------


Great Job! You have just completed making a Mouse Macro. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.

And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.

Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making a Mouse Macro project myself so you can download the source file in the attachments.

Thank you.

Image

Re: How to make a Mouse Macro

Posted: Sat Mar 12, 2011 6:18 pm
by mandai
If the path should be predictable, why do we have a random value?
When I use this the speed value appears to have no effect.

Re: How to make a Mouse Macro

Posted: Sun Mar 13, 2011 5:09 am
by Usman55
Actually for me I think it works but I also am not sure because changing the speed doesn't makes much difference. And this is not my code, I took it from sythe.org so you can ask slashshot007.

Re: How to make a Mouse Macro

Posted: Sun Mar 13, 2011 7:03 am
by XTechVB
DO Not use 0,0,0 this wil block your mouse pointer. it happened to me, i had to shutdown the program manually from my keyboard.

Re: How to make a Mouse Macro

Posted: Sun Mar 13, 2011 7:17 am
by Usman55
And also don't set the speed more than 5. If you do so, your mouse pointer will stay at one place and won't move. And so you will have to kill the process.

Re: How to make a Mouse Macro

Posted: Sun Mar 13, 2011 2:08 pm
by mandai
If I were to use my own mouse moving function I would do it this way:
Code: Select all
    Sub moveMouse(ByVal pointA As Point, ByVal pointB As Point, ByVal steps As Integer, ByVal wait As Integer)

        Dim incrementX As Integer = (pointB.X - pointA.X) / steps
        Dim incrementY As Integer = (pointB.Y - pointA.Y) / steps

        Cursor.Position = pointA
        Threading.Thread.Sleep(wait)
        For i As Integer = 0 To steps - 1
            Dim xtemp As Integer = pointA.X + (incrementX * i)
            Dim ytemp As Integer = pointA.Y + (incrementY * i)
            Cursor.Position = New Point(xtemp, ytemp)
            Threading.Thread.Sleep(wait)
        Next
        Cursor.Position = pointB
    End Sub

    Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click

        moveMouse(Cursor.Position, New Point(400, 400), 50, 50)

    End Sub

Re: How to make a Mouse Macro

Posted: Sun Mar 13, 2011 5:43 pm
by Usman55
I know your way is better but I never said I made the code. I took it from Sythe.org And because of advancement of a code, +rep!