Hello all, I know this topic has already been discussed multiple times but I can't figure out what is wrong with my code. I would like to send a mouse click to a window without focus. The following piece of code is creating a GUI with a "test" button. Clicking on the "test" button print a "ok" to the console. When pressing the keys CTRL + P, the VirtualMouseClick() function is called. This function calls the following : _SendMessage($hwnd, $WM_LBUTTONDOWN, 1, _WinAPI_MakeLong($x1, $y1))
_SendMessage($hwnd, $WM_LBUTTONUP, 0, _WinAPI_MakeLong($x1, $y1))Which should do what I want.. but it doesn't. Could you help me with it please ? Thank you Here is the code: #include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
;~ Opt("MustDeclareVars", 1)
HotKeySet("^p", VirtualMouseClick)
Global $gui
Global $size[2] = [300, 300]
$gui = GUICreate("", $size[0], $size[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $gui)
GUICtrlCreateButton("Test", 10, 10, 100, 80)
GUICtrlSetOnEvent(-1, "TestOk")
GUISetState(@SW_SHOW, $gui)
ConsoleWrite($gui & @CRLF)
While(True)
Sleep(200)
WEnd
Func _ArrayFind($array, $item)
Local $retour = False
For $i = 0 To UBound($array) -1
If($array[$i] = $item) Then
$retour = True
ExitLoop
EndIf
Next
Return $retour
EndFunc
Func quit()
Exit
EndFunc
Func TestOk()
ConsoleWrite("ok" & @CRLF)
EndFunc
Func VirtualMouseClick()
Sleep(100)
Local $hwnd = WinGetHandle("[ACTIVE]")
Local $x1 = 30
Local $y1 = 50
Local $isDown = 1
ConsoleWrite("$hwnd = " & $hwnd & @LF)
;~ _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
;~ Sleep(50)
_SendMessage($hwnd, $WM_LBUTTONDOWN, 1, _WinAPI_MakeLong($x1, $y1))
;~ Sleep(50)
;~ _SendMessage($hwnd, $WM_MOUSEMOVE, 1, _WinAPI_MakeLong($x1, $y1))
Sleep(50)
_SendMessage($hwnd, $WM_LBUTTONUP, 0, _WinAPI_MakeLong($x1, $y1))
EndFunc