Jump to content

Recommended Posts

Posted

Hi, new to Autoit,

I wish to ControlClick two different windows of the same Notepad program (for example)

I can only get it to work with one window like this:

$note=WinWait("Notepad")
$hWnd=ControlGetHandle($note,"","Edit1")

ControlClick($note,"",$hWnd,"left",1,Random(670,750),Random(461,539))

Posted

Hi Danp2, thanks, I've seen this repeating in other threads but I don't know how to refer to the correct window's handle every time...

I put Notepad for example only, the real reason is to click two windows of the same program (which I can't mention publicly on the internet - military project)

I don't understand how the array system works and all I have found that is remotely close is this script:

#include <Array.au3> ; Just for display of the window array

HotKeySet("{ESC}", "MyExit")
HotKeySet("{f2}", "getWinList")
HotKeySet("{f3}", "Start")

Global $aWinList

While 1
    sleep(10)
WEnd
Func MyExit()
    Exit
EndFunc   ;==>MyExit

Func getWinList()
    $iOldMode = Opt("WinTitleMatchMode", 2)
    $aWinList = WinList("Edit")
    Opt("WinTitleMatchMode", $iOldMode)
    _ArrayDisplay($aWinList, "", Default, 2)
EndFunc

Func Start()
    ; Loop through the array of matching windows
    For $i = 1 To $aWinList[0][0]
        ; Extract the handle from the array
        $hWnd = HWnd($aWinList[$i][1])
        ; Now run a minimize/restore cycle on each Notepad window to show that it works for each
        WinSetState($hWnd, "", @SW_MINIMIZE)
        Sleep(1000)
        WinSetState($hWnd, "", @SW_RESTORE)
        Sleep(1000)
    Next
EndFunc   ;==>Start

How do I name each $hWnd to refer to the window that I want to control?
Instead of using the WinSetState, could you show me how to ControlClick instead?
Say I want to ControlClick 1 window and then ControlClick the other window, how do I refer to their title and hWnd everytime?

I need my script to look like this:

;find hwnd of each window and refer to it
while 1 
ControlClick(title1,"",$hWnd1,"left",1,coords,coords)
ControlClick(title2,"",$hWnd2,"left",1,coords,coords)

WEnd

Thanks a lot!

Posted

Is this correct? 

Global $wList=WinList("Title")
ControlClick($wList[1][0],"",$wList[1][1],"left",1,Random(670,750),Random(461,539))

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
×
×
  • Create New...