Results 1 to 4 of 4

Thread: How to simulate mouse click?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    3
    How can I simulate a mouse click in a program? I've been able to make the mouse move by itself, but now I'd like to know how to make it click on a button, for instance.

    Thanks.

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    a button in ur own program?

    say ur butten name is command1

    so then just do this

    private sub timer1.timer ()
    command1_click
    end sub

    simple eh?


  3. #3
    New Member
    Join Date
    Jun 2000
    Posts
    3

    Thumbs down

    How can you simulate a click if its in another program?? I know its possible, and you have to use api, i think. somethin about WM_LBUTTONDOWN err somethin like that. I really need to know how to do this too, so anyone who knows please tell me!!

  4. #4
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112
    I recently tried something similar. I used the following
    code and although the third party application button
    appeared to be pressed, the click event was not being fired
    off. Maybe the code will work for you though.

    Code:
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As Any, ByVal lpszWindow As Any) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
    
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    
    Private Sub Command1_Click()
        Dim hwnd As Long
       
        hwnd = FindWindow(CLng(0), "WINDOW_CAPTION_GOES_HERE")
        
        'Has the window been found?
        If hwnd <> 0 Then
       
            Dim hWndCommandButton As Long
            
            hWndCommandButton = FindWindowEx(hwnd, 0, CLng(0), "BUTTON_CAPTION_GOES_HERE")
    
            'Has the Button control been found?
            If hWndCommandButton <> 0 Then                
                Call SendMessage(hWndCommandButton, WM_LBUTTONDOWN, 0, 0&)
                Call SendMessage(hWndCommandButton, WM_LBUTTONUP, 0, 0&)
            End If
        End If
    End Sub
    Good Luck.

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