Ok so the other day i was playing a game on facebook and decided to make a program to make it faster to play the game and save some time.

i made a simple auto clicker with some hotkeys to start/stop and then added some text boxes and some more hot keys to print what was in the textbox's

this was fine and i was happy with it till i seen this
http://www.youtube.com/watch?v=AlAASmyJ41g

now i want to make some thing like that but i want to use W,A,S,D keys to move the mouse around.

I am not sure how that guy made his but i want a way to make it and maybe even faster. so i can add it to my program.

here is my code for V1.2

Public Class FarmTownFarmer
    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub ClickOn_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClickOn.Tick
        Dim ClickOn As Boolean
        ClickOn = GetAsyncKeyState(Keys.F3)
        If ClickOn = True Then
            Clicker.Start()
        End If

    End Sub
    Private Sub ClickOff_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClickOn.Tick
        Dim ClickOff As Boolean
        ClickOff = GetAsyncKeyState(Keys.F4)
        If ClickOff = True Then
            Clicker.Stop()
        End If
    End Sub
    Private Sub MyMethod()
        Windows.Forms.Cursor.Position = New System.Drawing.Point(Windows.Forms.Cursor.Position)
        mouse_event(&H2, 0, 0, 0, 1)
        mouse_event(&H4, 0, 0, 0, 1)
    End Sub
    Private Sub Clicker_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clicker.Tick
        MyMethod()
        Clicker.Interval = SpeedSet.Text
    End Sub
    Private Sub SpeedTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SpeedTest.Click
        Speed.Text = Speed.Text + 1
    End Sub

    Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        Speed.Text = 0
    End Sub

    Private Sub MessHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MessHelp.Click
        MsgBox("Welcome to message box Help" & vbNewLine & _
            "The Message box system is easy to use." & vbNewLine & _
            "Step 1 Enter text in 1 of the 4 boxes." & vbNewLine & _
            "Step 2 Use your mouse to enter a" & vbNewLine & _
            "place where you type text." & vbNewLine & _
            "Step 3 Press The Key that is above the Box you." & vbNewLine & _
            "Put the message in. (F5,F6,F7,F8).")

    End Sub

    Private Sub AutoHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Welcome to AutoClicker Help" & vbNewLine & _
        "F3 & F4 start/stop the clicker." & vbNewLine & _
        "You can set the speed buy changing." & vbNewLine & _
        "the number after Click Every:" & vbNewLine & _
        "Test the Click speed By holding mouse over" & vbNewLine & _
        "the Speed Test Button" & vbNewLine & _
        "Will work on any window at any speed")
    End Sub

    Private Sub Message1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message1.Tick
        Dim Message1 As Boolean
        Message1 = GetAsyncKeyState(Keys.F5)
        If Message1 = True Then
            SendKeys.Send(Mess1.Text)
            SendKeys.Send("{Enter}")
        End If
    End Sub
    Private Sub Message2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message1.Tick
        Dim Message2 As Boolean
        Message2 = GetAsyncKeyState(Keys.F6)
        If Message2 = True Then
            SendKeys.Send(Mess2.Text)
            SendKeys.Send("{Enter}")
        End If
    End Sub
    Private Sub Message3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message1.Tick
        Dim Message3 As Boolean
        Message3 = GetAsyncKeyState(Keys.F7)
        If Message3 = True Then
            SendKeys.Send(Mess3.Text)
            SendKeys.Send("{Enter}")
        End If
    End Sub
    Private Sub Message4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message1.Tick
        Dim Message4 As Boolean
        Message4 = GetAsyncKeyState(Keys.F8)
        If Message4 = True Then
            SendKeys.Send(Mess4.Text)
            SendKeys.Send("{Enter}")
        End If
    End Sub

End Class

version V.1 never was finished because of the fail hot key system i was using was not global it was only working if you had the form active

there are alot of things in my code and on my form

4 buttons
6 textboxes
7 timers

so what i want to know is how can i find the mouse pos then do a load of math on it so that it moves the mouse over each square with in a range of the mouse.

Why hasn't any 1 helped me Now i have no mothers day gift Dang nabit

i just need the mouse to move in a direction when a button is pressed

>i just need the mouse to move in a direction when a button is pressed


What is the problem with Cursor.Position?

The problem being i don't know how to use it

I did some playing around and Found the X and the Y of my mouse and displayed it i then made it move to a set spot on the screen

what i can't work out how to do it find its current spot then add a number to it like i need

mouse pos.X +2

and have that inside the key or some thing and make the mouse setpos to what ever that = every way i tried doing it i ended up with a load of errors

Because this it like only my second ever Vb 2008 project......

Hi,

You could use something like this:

Dim x As Integer
        Dim y As Integer
        Cursor.Position = New Point(x + 2, y) 
       Cursor.Position = New POint(X, Y +2)

your code is all well land good but it dose not get the mouse currant spot and then add on the number this is a problem

im playing around with it again will see how i go

SOLVED Thank you for the record here is the code i am using that is moving my mouse

Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Declare Function SetCursorPos& Lib "user32" (ByVal p As Point)

Private Sub TicW_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TicW.Tick
        Dim TicW As Boolean
        Dim MoX As Integer
        Dim MoY As Integer
        Dim P As Point
        TicW = GetAsyncKeyState(Keys.W)
        MoX = MousePosition.X
        MoY = MousePosition.Y
        If TicW = True Then
            P.Y = MoY - 10
            P.X = MoX
            SetCursorPos(P)
        End If
    End Sub

End Class

Please not that TicW is a timer is checks to see if W is pressed and then the code acts if that is true

I used some of what you gave me above and some other bits i found in google combined with some of my logic.

thanks for your help

Hi,

No problem glad to help.
Mark it as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.