• Log in or sign up for an account here: https://www.sythe.org/login

Moving Mouse to X,Y Position

Agoz

Newcomer
Joined
Sep 13, 2009
Sythe Gold
0
Messages
5
Moving Mouse to X,Y Position
Hello this is my second thread! ;)

This time I'm wondering if there are any tutorials or how to make the mouse itself or a "second" mouse to move to a position on screen? And how would I do to make it random move and click somewhere between a "rectangle" on screen? :huh:

Thanks for help.

Agoz :D
 
Moving Mouse to X,Y Position
Code:
        Windows.Forms.Cursor.Position = New System.Drawing.Point(X, Y)

Will move it to the position inserted into the System.Drawing.Point. To click in a rectangle, do some math and find a random point inside your rectangle, then use a variable or two, or even just do the math in the function.

~Sandstorm
 
Moving Mouse to X,Y Position
here is some code to preform ma mouse click and also move the mouse
Code:
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
    Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Integer
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
    Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
    Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
    Public Sub MouseLeftClick()
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        Sleep(50)
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub

 Cursor.Position = New Point(100, 100)


        SetCursorPos(330, 288)
        MouseLeftClick()
here is some code to put the mouse x,y in a textbox
Code:
   Dim mouseLocation As Point = Windows.Forms.Cursor.Position

        TextBox1.Text = "X: " & mouseLocation.X.ToString

        TextBox2.Text = "Y: " & mouseLocation.Y.ToString
 
Moving Mouse to X,Y Position
Thanks but I wasn't clear enough sorry, I mean like how to make it a "second mouse" and make it MOVE to that position like a real mouse not "teleporting" Like some bot clients do...

Thanks
/Agoz :D
 
Moving Mouse to X,Y Position
Use a loop that moves it pixel by pixel. Maybe not the best way, but it's an idea.
 
Moving Mouse to X,Y Position
SendMessage.
Oh how hard.
PS ipivb: mouse_event is old and ugly. Use SendInput instead.
Code:
    INPUT input;
    input.mi.dx = <move x>;
    input.mi.dy = <move y>;
    input.mi.mouseData = 0;
    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
    input.mi.time = 0;
    input.type = INPUT_MOUSE;
    SendInput(1, &input, sizeof(INPUT));
Above is C code, just convert it to VB.
 
Moving Mouse to X,Y Position
Something I quickly wrote, works smoothly :p This was the only method I could think of, it's pretty simple and all.

Code:
Private Declare Sub mouse_event Lib "user32.dll" ( _
    ByVal dwFlags As Int32, _
    ByVal dx As Int32, _
    ByVal dy As Int32, _
    ByVal cButtons As Int32, _
    ByVal dwExtraInfo As Int32 _
    )

    Private Declare Function SetCursorPos Lib "user32.dll" ( _
    ByVal X As Int32, _
    ByVal Y As Int32 _
    ) As Boolean

    Public Sub moveMouse(ByVal TargetX As Integer, ByVal targetY As Integer)
        Dim X As Integer = MousePosition.X, y As Integer = MousePosition.Y

        Do Until X = TargetX And y = targetY
            If (X > TargetX) Then
                X = X - 1
            End If
            If (X < TargetX) Then
                X = X + 1
            End If
            If (y > targetY) Then
                y = y - 1
            End If
            If (y < targetY) Then
                y = y + 1
            End If
            SetCursorPos(X + New Random().Next(3, 4), y + New Random().Next(3, 4))
            Threading.Thread.Sleep(10)
        Loop
    End Sub


Usage: moveMouse(x, y)

Planning to use this? Please credit Coron <[email protected]> :)
 
Moving Mouse to X,Y Position
Something I quickly wrote, works smoothly :p This was the only method I could think of, it's pretty simple and all.

Code:
Private Declare Sub mouse_event Lib "user32.dll" ( _
    ByVal dwFlags As Int32, _
    ByVal dx As Int32, _
    ByVal dy As Int32, _
    ByVal cButtons As Int32, _
    ByVal dwExtraInfo As Int32 _
    )

    Private Declare Function SetCursorPos Lib "user32.dll" ( _
    ByVal X As Int32, _
    ByVal Y As Int32 _
    ) As Boolean

    Public Sub moveMouse(ByVal TargetX As Integer, ByVal targetY As Integer)
        Dim X As Integer = MousePosition.X, y As Integer = MousePosition.Y

        Do Until X = TargetX And y = targetY
            If (X > TargetX) Then
                X = X - 1
            End If
            If (X < TargetX) Then
                X = X + 1
            End If
            If (y > targetY) Then
                y = y - 1
            End If
            If (y < targetY) Then
                y = y + 1
            End If
            SetCursorPos(X + New Random().Next(3, 4), y + New Random().Next(3, 4))
            Threading.Thread.Sleep(10)
        Loop
    End Sub


Usage: moveMouse(x, y)

Planning to use this? Please credit Coron <[email protected]> :)

How would that code be like if I would like it to move the cursor to 245, 565 ?
 
Runescape Gamblingrunescape gambling
Back
Top