Results 1 to 4 of 4

Thread: Mouse controls, how to emulate clicks ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    129

    Question

    How do I emulate mouse clicks using code ? I want the mouse to actually click on something, and not JUST trigger an event.

    What I am trying to do:
    I am trying to set a timer to click the mouse on an X/Y Pos.
    BaLLZaCH

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    'Before you start this program, I suggest you save everything that wasn't saved yet.
    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)
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Const MOUSEEVENTF_MIDDLEUP = &H40
    Const MOUSEEVENTF_MOVE = &H1
    Const MOUSEEVENTF_ABSOLUTE = &H8000
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10
    Private Sub Form_Activate()
    Do
            'Simulate a mouseclick on the cursor's position
            mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, cButt, dwEI
            DoEvents
        Loop
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    129
    Thanks. Works perfect. Check out the program
    I built on download.com or my web site. It is
    called BZAutoSurf.exe - Its cool, I promise.
    BaLLZaCH

  4. #4
    Guest
    Try this:
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    Private Sub Form_Load()
        Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
        Dim PT As POINTAPI
        Dim WND As Long
        GetCursorPos PT
        WND = WindowFromPoint(PT.x, PT.y)
        PostMessage WND, WM_LBUTTONDOWN, MK_LBUTTON, 0
        PostMessage WND, WM_LBUTTONUP, MK_LBUTTON, 0
    End Sub

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