adijian Posted May 22, 2020 Posted May 22, 2020 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))
Danp2 Posted May 22, 2020 Posted May 22, 2020 You could use the WinList function to get an array of matching windows. Then use the hWnd representing the window's handle to control which window your click is directed towards. Clearly you don't intend to send random clicks to a notepad window. Why don't you tell us your real intentions? Latest Webdriver UDF Release Webdriver Wiki FAQs
adijian Posted May 22, 2020 Author Posted May 22, 2020 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!
Danp2 Posted May 22, 2020 Posted May 22, 2020 You would need to change the following line so that it targets your desired window -- $aWinList = WinList("<Your window title goes here>") The code in the Start function loops through the array, grabs the handle for each window, and then does something with it. You would want to take this handle and pass it as the initial parameter for ControlClick. Latest Webdriver UDF Release Webdriver Wiki FAQs
adijian Posted May 22, 2020 Author Posted May 22, 2020 Is this correct? Global $wList=WinList("Title") ControlClick($wList[1][0],"",$wList[1][1],"left",1,Random(670,750),Random(461,539))
Danp2 Posted May 22, 2020 Posted May 22, 2020 Nope. You don't need $wList[1][0]. Instead pass $wList[1][1], the window handle, as the first parameter -- ControlClick($wList[1][1],"", <Need control info here>,"left",1,Random(670,750),Random(461,539)) As indicated, you still need to provide info to indicate the control to be clicked. P.S. Please read this post on how to properly post code on the forum Latest Webdriver UDF Release Webdriver Wiki FAQs
adijian Posted May 22, 2020 Author Posted May 22, 2020 Thanks, it works now. BTW here only for this question... not everyone is prepped up to forum codes on the first thread
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now