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

Thread: Send Clicks

  1. #1
    Join Date
    May 2001
    Posts
    155

    Send Clicks

    I know how to send keys, but is there a way to send double click?
    Thanks in advance

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: christopherfolger@hotmail.com
    for the address

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Send Clicks

    Use the mouse_event() API or the SendInput() API function.


  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: Send Clicks

    what's the code for that?

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: christopherfolger@hotmail.com
    for the address

  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Send Clicks

    Here's the code for you.


    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 Const MOUSEEVENTF_RIGHTDOWN = &H8
    private Const MOUSEEVENTF_RIGHTUP = &H10
    private Const MOUSEEVENTF_ABSOLUTE = &H8000
    private Declare Function SetCursorPos Lib "user32" (byval x as Long, byval y as Long) as Long

    private Sub Command1_Click()
    'Simulate a double click as a quick series of two clicks
    SetCursorPos 100, 100
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Sub

    private Sub Command2_Click()
    'Open the start menu in my display set at 1024*768
    SetCursorPos 20, 760
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Sub

    private Sub Form_DblClick()
    MsgBox "I've been double clicked"
    End Sub

    private Sub Form_Load()
    me.Left = 0
    me.Top = 0
    End Sub







    Note that LEFTBUTTON to mouse_event means the physical left button, you should detect if the user has swapped buttons and make appropriate adjustments.


  5. #5
    Join Date
    Oct 2009
    Posts
    1

    Re: Send Clicks

    What are the declaration of these for?
    private Const MOUSEEVENTF_LEFTDOWN = &H2
    private Const MOUSEEVENTF_LEFTUP = &H4

    does it mean that in user32.dll, the events definition is &H2.. H4... ? I mean, is it like somewhere they have #define MOUSEEVENTF_LEFTDOWN &H2 or something like that?

    and where I can find how these events are defined in the library?
    so in another way, I can just type mouse_event &H2, 0, 0,0,0 ?

    thanks

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Send Clicks

    Yes you can. It is like you assumed.
    There is a define MOUSEEVENTF_LEFTDOWN 0x02 where 0x02 is the syntax for hexadecimal &H2. In C these definitions exist in .h files which are included in compilation when programming in C.
    We VB guys have to make a similar definition if we want better readable code.
    mouseevent 2,0,0,0,0 is telling nothing while
    mouseevent MOUSEEVENTF_LEFTDOWN, 0,0,0,0 explains everything.
    Still after years it is selfexplanatory, while you might forget what the &H2 was.
    The equivalent or replacement of the define statement in C is
    Private (or Public) Constant MOUSEEVENTF_LEFTDOWN = 2


    I'd like to point you to this site here: http://allapi.mentalis.org/apilist/apilist.php
    From there you can download a little utility called API-Viewer, which informs you about the values of any (or most) constants.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center