CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Generate Mouse Events

    I've figured out how to set the mouse pointer X and Y positions with the API call SetCursorPos, but how can I generate a left mouse click? I tried this:

    SendMessage 0, 513, 0, 0

    (Where 513 = WM_LBUTTONDOWN)

    But this had no effect.

    Any ideas anyone? thanks

    Nick



  2. #2
    Join Date
    Jul 1999
    Posts
    34

    Re: Generate Mouse Events

    Put this into a module
    and use mouseclick (button)

    public Function MouseClick(byval MBClick as enButtonToClick) as Boolean

    Dim cbuttons as Long
    Dim dwExtraInfo as Long
    Dim mevent as Long

    Select Case MBClick
    Case mLeft
    mevent = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP
    Case mRight
    mevent = MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP
    Case mMiddle
    mevent = MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP
    Case else
    MouseClick = false
    Exit Function
    End Select

    mouse_event mevent, 0&, 0&, cbuttons, dwExtraInfo
    MouseClick = true

    End Function





  3. #3
    Join Date
    Jul 1999
    Posts
    34

    Re: Sorry!!! Forgot

    Add this to module:

    private Const MOUSEEVENTF_ABSOLUTE = &H8000
    private Const MOUSEEVENTF_LEFTDOWN = &H2
    private Const MOUSEEVENTF_LEFTUP = &H4
    private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    private Const MOUSEEVENTF_MIDDLEUP = &H40
    private Const MOUSEEVENTF_MOVE = &H1
    private Const MOUSEEVENTF_RIGHTDOWN = &H8
    private Const MOUSEEVENTF_RIGHTUP = &H10

    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)
    public Enum enButtonToClick
    mLeft
    mRight
    mMiddle
    End Enum
    public Function MouseClick(byval MBClick as enButtonToClick) as Boolean

    Dim cbuttons as Long
    Dim dwExtraInfo as Long
    Dim mevent as Long

    Select Case MBClick
    Case mLeft
    mevent = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP
    Case mRight
    mevent = MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP
    Case mMiddle
    mevent = MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP
    Case else
    MouseClick = false
    Exit Function
    End Select

    mouse_event mevent, 0&, 0&, cbuttons, dwExtraInfo
    MouseClick = true

    End Function






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

Featured