Results 1 to 6 of 6

Thread: Sending mouse clicks to other applications

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    2

    Exclamation

    How can I send mouse clicks to other applications? Please give me the exact syntax to send a LeftButtonClick, to the client area of another application

  2. #2
    Guest
    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 Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    Private Sub Command1_Click()
        'Send a click to a window
        PostMessage HwndOfWindow, WM_LBUTTONDOWN, MK_LBUTTON, 0
        PostMessage HwndOfWindow, WM_LBUTTONUP, MK_LBUTTON, 0
    End Sub

  3. #3
    Guest
    If your next question is how to get the hWnd of a Window, use the FindWindowEx API.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    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 Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    Private Sub Command1_Click()
        
        Dim HwndOfWindow As Long
        HwndOfWindow = FindWindowEx(0, 0, "SciCalc", "Calculator")
        
        If HwndOfWindow <> 0 Then
            'Click it
            PostMessage HwndOfWindow, WM_LBUTTONDOWN, MK_LBUTTON, 0
            PostMessage HwndOfWindow, WM_LBUTTONUP, MK_LBUTTON, 0
        End If
        
    End Sub

  4. #4
    Member
    Join Date
    Jul 2007
    Posts
    44

    Re: Sending mouse clicks to other applications

    how do u specify coordinates...

  5. #5
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: Sending mouse clicks to other applications

    Code:
    Me.Cursor.Position = New Point(x, y)
    thats for moving the mouse to certain coordinates, not sure about clicking though.
    i think i have a project on laptop that includes that, if i find it ill inform you.


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  6. #6

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