Results 1 to 5 of 5

Thread: Moving the mouse with a VB program

  1. #1
    Guest

    Post

    I get the mouse to move through vb? like move it from one corner to another corner? Or something to this exstant?

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    There is an answer in vb-world tips under mouse/keyboard.

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Location
    Thessaloniki ,Greece
    Posts
    100

    Post

    Put this in a module

    Option Explicit

    Type POINTAPI
    x As Long
    y As Long
    End Type

    Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

    And Final Put this to an form and create a command button called command1


    Sub MoveMouse(x As Single, y As Single)
    Dim pt As POINTAPI
    pt.x = x
    pt.y = y
    ClientToScreen hwnd, pt
    SetCursorPos pt.x, pt.y
    End Sub

    Private Sub Command1_Click()
    MoveMouse 300, 150
    End Sub

    Final if you click the button mouse moves in 300,150 position(x,y) of your form
    With MoveMouse procedure you can put mouse cursor in x,y position like

    MoveMouse x,y

    To make mouse to move in a line you can use this procedure

    Sub domove(px1, py1, px2, py2 As Single)
    Dim pb As Single
    Dim i As Single
    Dim pyold As Single
    If (px1 - px2) <> 0 Then
    pb = (py1 - py2) / (px1 - px2) '
    pyold = py1
    If (px1 - px2) < 0 Then
    For i = px1 To px2
    If (py1 - py2) < 0 Then
    pyold = Abs(py1 + (i - px1) * pb)
    MoveMouse Abs(Int(i)), Abs(Int(pyold))
    End If
    If (py1 - py2) > 0 Then
    pyold = Abs(py1 + (i - px1) * pb)
    MoveMouse Abs(Int(i)), Abs(Int(pyold))
    End If
    Next i
    End If
    If (px1 - px2) > 0 Then
    For i = px1 To px2 Step -1
    If (py1 - py2) < 0 Then
    pyold = Abs(py1 + (i - px1) * pb)
    MoveMouse Abs(Int(i)), Abs(Int(pyold))
    End If
    If (py1 - py2) > 0 Then
    pyold = Abs(py1 + (i - px1) * pb)
    MoveMouse Abs(Int(i)), Abs(Int(pyold))
    End If
    Next i
    End If
    End If
    End Sub

    Use it like this

    domove (0,0,400,300)

    This move mouse pointer from 0,0 position to 400,300 position

    It's simple code.... bye

    Created By Antony Tsiukas


  4. #4
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Be careful! I wouldn't like my mouse roaming all over my desktop!

    ------------------
    I wish I was patient... RIGHT NOW!

  5. #5
    Guest

    Post

    i guess i got my answer from the article.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width