Results 1 to 5 of 5

Thread: Moving a mouse by application driven

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    1

    Moving a mouse by application driven

    Is it possible to drive a mouse out of a vb-application?
    - mouse moving over the screen
    - clicking

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Moving a mouse by application driven

    Welcome to the forums

    I think you will have to give much more information/details. I, for one, cannot determine what you are asking. Too general
    Suggest taking a few minutes and reading the Hitchhiker's Guide, linked in my signature below
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Addicted Member
    Join Date
    Jun 2010
    Location
    The Keystone State
    Posts
    131

    Re: Moving a mouse by application driven

    Sounds like he wants to use a vb app to hook the mouse and auto control it over the screen and auto click it, taking control away from the user. The question is ...Why?

  4. #4
    New Member
    Join Date
    Feb 2012
    Posts
    4

    Re: Moving a mouse by application driven

    try this:
    do this form


    then write this in the form:
    Code:
    Dim k
    Private Sub Command1_Click()
    Call mouse_event(MOUSEEVENTF_MOVE, -k, 0, 0, 0)
    End Sub
    Private Sub Command2_Click()
    Call mouse_event(MOUSEEVENTF_MOVE, 0, -k, 0, 0)
    End Sub
    Private Sub Command3_Click()
    Call mouse_event(MOUSEEVENTF_MOVE, k, 0, 0, 0)
    End Sub
    Private Sub Command4_Click()
    Call mouse_event(MOUSEEVENTF_MOVE, 0, k, 0, 0)
    End Sub
    Private Sub Command5_Click()
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub
    Private Sub Command6_Click()
    Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
    End Sub
    Private Sub Command7_Click()
    Call mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
    End Sub
    Private Sub Form_Load()
    k = 4
    'greater k will result in more amount of movment of the pointer
    End Sub
    
    
    'You can also use mouse wheel using this:
    'd is the amout of movement
    'positive d goes up and negative d goes down
    'd=120
    'Call mouse_event(MOUSEEVENTF_WHEEL, 0, 0, d, 0)
    then add a module and write this:

    Code:
    Public 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 ' 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 Const MOUSEEVENTF_MOVE = &H1
    
    Public Const MOUSEEVENTF_MOUSEEVENTF_ABSOLUTE = &H8000
    Public Const MOUSEEVENTF_WHEEL = &H800

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Moving a mouse by application driven

    Herbie

    Regarding getting and setting the cursor position
    by code, something like this ..

    In declarations
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    In a sub .. (I just grabbed one I had .. modify as req'd)
    Code:
    Public Sub CurXbaby(cWhat, nZ1)
        '
        Dim CurPos As POINTAPI
        Dim PosX As Long, PosY As Long
        Dim pp As Long
        GetCursorPos CurPos
        PosX = CurPos.x
        PosY = CurPos.y
        '
        If cWhat = "show" Then
            SetCursorPos PosX - nZ1, PosY
        ElseIf cWhat = "reset" Then
            SetCursorPos PosX + nZ1, PosY
        End If
        '
    End Sub
    Spoo

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