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.
Printable View
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.
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?
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!!
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. :)
Good Luck.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