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
Printable View
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
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
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
how do u specify coordinates...
thats for moving the mouse to certain coordinates, not sure about clicking though.Code:Me.Cursor.Position = New Point(x, y)
i think i have a project on laptop that includes that, if i find it ill inform you.
You don't need to specify coordinates when using the "FindWindow" API...