Sign in to follow this  
Followers 0
MattH

Capturing mouse click location/object

3 posts in this topic

I understand how to capture return information from the controls that I create in a GUI. What I can't figure out is how to get "return" information from a control in another application. Specifically, I have a program that has an OK and Cancel button on it. I want to be able to know when those are pressed by the user. This is not a program I wrote so I can't get inside it. The Au3Info tool shows me that the controls are called Button1 and Button2. Sending a click is no problem, but I want to know when a click is received. Is that possible?

Share this post


Link to post
Share on other sites



get hwnd button (ControlGetHandle). get mousehook. compare hwnd mousehook to hwnd of you.

no resources, only high level idea. ~Jap

Share this post


Link to post
Share on other sites

fine. i have no faith of you.

run this and it tell you if Cancel of "Run" window clicked. need hook.dll provided

Const $WH_MOUSE = 7

Const $WM_AUTOITLBUTTONDOWN = 0x1400 + 0x0A30

$gui = GUICreate("test")

Global $DLLinst = DLLCall("kernel32.dll","hwnd","LoadLibrary","str",".\hook.dll")
Global $mouseHOOKproc = DLLCall("kernel32.dll","hwnd","GetProcAddress","hwnd",$DLLInst[0],"str","MouseProc")

Global $hhMouse = DLLCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_MOUSE, _
        "hwnd",$mouseHOOKproc[0],"hwnd",$DLLinst[0],"int",0)

DLLCall(".\hook.dll","int","SetValuesMouse","hwnd",$gui,"hwnd",$hhMouse[0])

GUIRegisterMsg($WM_AUTOITLBUTTONDOWN,"myfunc")

Send("#r")
WinWait("Run")

Global $smellyHWND = ControlGetHandle("Run","","Cancel")
Global $t = TimerInit()
Sleep(250)

While WinExists("Run")
    $msg = GUIGetMsg()
    If $msg = -3 Then ExitLoop
    ToolTip("click Cancel on Run window")
    If TimerDiff($t) < 250 Then
        Sleep(1000)
        Exit
    EndIf
WEnd

Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
    If HWnd($WParam) = $smellyHWND Then
        ToolTip("Run / Cancel clicked")
        $t = TimerInit()
    EndIf
EndFunc

Func OnAutoItExit()
    DLLCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hhMouse[0])
    DLLCall("kernel32.dll","int","FreeLibrary","hwnd",$DLLinst[0])
EndFunc

hook.dll

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0