Waiting for Controls to Load

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
avedium
Posts: 3
Joined: 04 May 2024, 12:32

Waiting for Controls to Load

04 May 2024, 13:32

Hello! I am new here so please let me know if I am violating any guidelines. (Also please forgive my ignorance in general).

I am attempting to write some scripts to automate repetitive tasks at work. I am unfamiliar with scripting and have been crawling the AutoHotkey V2 documentation in search of some guidance without success. Here is my current script:

Code: Select all

#Requires AutoHotkey v2.0

; BK  Dir = "CFC - BK" & PV Dir = "CFC"
winTitle := "Aloha Configuration Center : Quality Dining"

; Waits for the control to become available 
ControlWait(classNN)
{
	controlVisible := false
	while (controlVisible == false)
	{
		try
		{
			Sleep 100
			controlVisible := ControlGetVisible(classNN, winTitle)
		}
	}
	
	return 0
}

; Exports Data Distribution reports! 
ExportDD(CFCDirectory, suffix)
{
	; Launch CFC
	Run "C:\BootDrv\" . CFCDirectory . "\ShellInstaller\CFCShellBootstrapper.exe"
	
	; Wait for user to press enter after typing password
	KeyWait "Enter", "D"
	
	; Export DD
	ControlWait("WindowsForms10.Window.8.app.0.58072d_r9_ad12") ; Wait for "Reports" to be visible
	ControlClick("x60 y140", winTitle) ; Click "Reports"
	ControlClick("x60 y170", winTitle) ; Click (hover over?) "Aloha Configuration Center"
	ControlClick("x60 y170", winTitle) ; Click Data Distribution
	ControlWait("WindowsForms10.COMBOBOX.app.0.58072d_r9_ad11") ; Wait for store selection to load
	ControlClick("x170 y230", winTitle) ; Click "Sort By"
	ControlClick("x170 y280", winTitle) ; Click "Last Export Time"
	ControlClick("x170 y270", winTitle) ; Click "Select All" 
	ControlClick("x210 y730", winTitle) ; Click "Generate Report"
	Sleep 5000 ; Wait for export to load
	ControlClick("x170 y190", winTitle) ; Click "Export"
	Send "^lC:\Users\alentine\OneDrive - Quality Dining, Inc\Documents\Records\Data Distribution{Enter}" ; Navigate to the DD reports folder
	Send "{Tab 6}DD " . FormatTime(A_Now, "ShortDate") . " " . suffix . "{Enter}" ; Type in the name and date for the DD export and press enter
	WinClose (winTitle) ; Close CFC
	
	return 0
}

ExportDD("CFC - BK", "Fast")
ExportDD("CFC", "Full")
I eventually determined I needed to add the "D" parameter to KeyWait for it to function at all. Unsure what I am doing wrong there...

My ControlWait function will not work at all. It will continue to try I am unable to find a solution to have the script wait for the control to load before pressing it. Window Spy returns this when selecting the control I wish the script to wait for:
image.png
image.png (67.49 KiB) Viewed 298 times
Any help, advice, or resources would be greatly appreciated!
User avatar
mikeyww
Posts: 27163
Joined: 09 Sep 2014, 18:38

Re: Waiting for Controls to Load

04 May 2024, 19:57

Welcome to this AutoHotkey forum!

You wish to wait for a specific control, but your script specifies only other values for ClassNN.

Your script does not need to test various clicks and multiple function calls. It needs to test only a single user-defined function call.

Ideas are below. I also tested your ControlWait function: it worked.

Code: Select all

#Requires AutoHotkey v2.0
SoundBeep 1500
controlWait('RichEditD2DPT1', 'ahk_exe Notepad.exe')
MsgBox 'Done!', 'Status', 'Iconi'

controlWait(classNN, winTitle) {
 WinWait winTitle
 SoundBeep 2500
 Loop {
  Try If ControlGetVisible(classNN, winTitle)
   Return
  Sleep 50
 }
}
avedium
Posts: 3
Joined: 04 May 2024, 12:32

Re: Waiting for Controls to Load

05 May 2024, 12:25

Thank you, mikeyww! You rock :D

Revised script:

Code: Select all

#Requires AutoHotkey v2.0

; Waits for the control to become available 
ControlWait(classNN, winTitle)
{
	SoundBeep 500
	
	WinWait winTitle
	SoundBeep 1500
	
	loop
	{
		try if ControlGetVisible(classNN, winTitle) 
		{
			SoundBeep 2500
			return 0
		}
		sleep 50
	}
	
	return 1
}

; Exports Data Distribution reports! 
ExportDD(CFCDirectory, suffix, winTitle := "Aloha Configuration Center : Quality Dining")
{
	; Launch CFC
	Run "C:\BootDrv\" . CFCDirectory . "\ShellInstaller\CFCShellBootstrapper.exe"
	
	; Wait for user to press enter after typing password
	KeyWait "Enter", "D"
	
	; Export DD
	ControlWait("WindowsForms10.Window.8.app.0.58072d_r9_ad12", winTitle) ; Wait for "Reports" to be visible
	sleep 5000
	ControlClick("x60 y140", winTitle) ; Click "Reports"
	ControlClick("x60 y170", winTitle) ; Click (hover over?) "Aloha Configuration Center"
	ControlClick("x60 y170", winTitle) ; Click Data Distribution
	MsgBox "I tried to click some buttons on the toolbar"
	
	ControlWait("WindowsForms10.COMBOBOX.app.0.58072d_r9_ad11", winTitle) ; Wait for store selection to load
	sleep 5000
	ControlClick("x170 y230", winTitle) ; Click "Sort By"
	ControlClick("x170 y280", winTitle) ; Click "Last Export Time"
	ControlClick("x170 y270", winTitle) ; Click "Select All" 
	ControlClick("x210 y730", winTitle) ; Click "Generate Report"
	MsgBox "I tried generate the DD report for " . suffix
	sleep 5000 ; Wait for export to load
	
	ControlClick("x170 y190", winTitle) ; Click "Export"
	MsgBox "I tried to click export." 
	Send "^lC:\Users\alentine\OneDrive - Quality Dining, Inc\Documents\Records\Data Distribution{Enter}" ; Navigate to the DD reports folder
	Send "{Tab 6}DD " . FormatTime(A_Now, "ShortDate") . " " . suffix . "{Enter}" ; Type in the name and date for the DD export and press enter
	MsgBox "I tried to name and save the file." 
	WinClose (winTitle) ; Close CFC
	
	return 0
}

ExportDD("CFC - BK", "Fast")
ExportDD("CFC", "Full")
I should have clarified what I am attempting to accomplish a little more clearly. Step-by-step, I wish to create a script that accomplishes the following:
1. Opens a specific application (Aloha Configuration Center or CFC as jargon).
2. Waits for the user to enter a password.
3. Waits for the application to load.
4. Navigates through the application and opens a save file as window...
a. Clicks some buttons on the toolbar.
b. Waits for the application to load.
c. Clicks some more buttons...
d. Waits for the file preview to load
e. Clicks "Export"
5. Navigates to documents in the file explorer window. Enters the date, and a suffix as the file name then saves.
6. Closes the application

I hope that clears up why I have several CommandClick lines.

The current obstacle I am dealing with is getting AutoHotkey to click the controls in Configuration center. I can see the commands being processed in the logs, but none of the buttons are being pressed. Unfortunately, the entire toolbar for CFC has one ClassNN. Is there any way to get more granular information about controls that AutoHotkey can understand?

P.S. - SoundBeep is my new favorite command. Hot Cross Buns incoming.
User avatar
mikeyww
Posts: 27163
Joined: 09 Sep 2014, 18:38

Re: Waiting for Controls to Load

05 May 2024, 12:46

If you are using coordinates, you can use Click instead of ControlClick.

You might want to have a look at forum posts about UI Automation.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: bang2010 and 35 guests