Results 1 to 3 of 3

Thread: Mouse automatically click?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    33

    Post

    How can i get the mouse to automatically click???? Like on its own

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Use the Mouse_Event API, eg.
    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 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)
    
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    
    Private Sub Command1_Click()
        Dim tPoint As POINTAPI
        Call GetCursorPos(tPoint)
        Call mouse_event(MOUSEEVENTF_LEFTDOWN, tPoint.x, tPoint.y, 0, 0)
        Call mouse_event(MOUSEEVENTF_LEFTUP, tPoint.x, tPoint.y, 0, 0)
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Two comments.
    1. You don't need to specify the dx and dy if the dwFlags doesn't include MOUSEEVENTF_ABSOLUTE. If you don't include it, the mouse_event procedure will move the cursor dx pixels to the right and dy pixels down. (0, 0) means don't move it at all.

    2. You can click in one call, by combining MOUSEEVENTF_LEFTDOWN with MOUSEEVENTF_LEFTUP (&H2 Or &H4 = &H6).
    Code:
    Private 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)
    
    
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    
    
    Private Sub Command1_Click()
        Call mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub
    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879


    [This message has been edited by Yonatan (edited 11-06-1999).]

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