I presently do just that. I haven't had reliable luck getting the button text back if the window isn't the one with focus.
Yes the AutoIt Spy has been a HUGE help!
I oversimplified my problem but here is the whole script. I use ini files and such.
;
; AutoIt Version: 3.0
; Language: English
; Platform: Win9x/NT
; Author: Ryan Pusztai (ryan.pusztai@jci.com)
;
; Script Function:
; Checks for a specific window then sends a click event to the specified button
;
AutoItSetOption("TrayIconDebug", 1)
; Give the user a chance to quit
$answer = MsgBox (4, "AutoWinClose", "Run script?")
If $answer = 7 Then
Exit ;User didn't want to run script
EndIf
; Press Esc to terminate script, Pause/Break to pause
Global $Paused
Global $NumWindows
Global $SearchMode
Global $WinTitle[10]
Global $ButtonText[10]
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
If FileExists(@ScriptDir & "\config.ini") Then
;MsgBox(4096, "",@ScriptDir & "\config.ini exists.")
$NumWindows = IniRead(@ScriptDir & "\config.ini", "Setup", "NumWindows", "1")
$SearchMode = IniRead(@ScriptDir & "\config.ini", "Setup", "SearchMode", "2")
AutoItSetOption("WinTitleMatchMode", Number($SearchMode)) ; 2 = Match any substring in the title
For $i = 0 To $NumWindows
$WinTitle[$i] = IniRead(@ScriptDir & "\config.ini", "Windows", "WindowTitle" & String($i+1), "<Change>")
$ButtonText[$i] = IniRead(@ScriptDir & "\config.ini", "Windows", "Button" & String($i+1), "<Change>")
Next
Else
IniWrite(@ScriptDir & "\config.ini", "Setup", "NumWindows", "1")
IniWrite(@ScriptDir & "\config.ini", "Setup", "SearchMode", "2")
$file = FileOpen(@ScriptDir & "\config.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
FileWriteLine($file, "; SearchMode alters the method that is used to match window titles." & @LF)
FileWriteLine($file, "; 1 = Match the title from the start (default)" & @LF)
FileWriteLine($file, "; 2 = Match any substring in the title" & @LF)
FileWriteLine($file, "; 3 = Exact title match" & @LF)
FileWriteLine($file, "; 4 = Advanced mode" & @LF)
FileClose($file)
IniWrite(@ScriptDir & "\config.ini", "Windows", "WindowTitle1", "<Change>")
IniWrite(@ScriptDir & "\config.ini", "Windows", "Button1", "<Change>")
MsgBox(4096,"", "Please edit " & @ScriptDir & "\config.ini with your proper settings.")
Run("notepad.exe " & @ScriptDir & "\config.ini")
Exit
EndIf
;SplashTextOn("myMsgScreen", "Running")
;WinShow("pauseSpecialScrn", "", @SW_HIDE)
While 1;infinite loop
If $Paused then
Sleep(1000)
Else
PressButton ($WinTitle[0], "Button1", $ButtonText[0])
PressButton ($WinTitle[1], "AfxOleControl422", $ButtonText[1])
Sleep(1)
; stuff to do goes here ...
EndIf
Wend
Func TogglePause()
$Paused = NOT $Paused
;If $Paused then
;SplashTextOn("myMsgScreen", "Paused ...")
;Else
;SplashTextOn("myMsgScreen", "Running ...")
;EndIf
EndFunc
Func Terminate()
If MsgBox(52, "AutoWinClose", "Close AutoWinClose?") = 6 Then Exit
EndFunc
Func PressButton($Title, $Class, $ButText)
If WinExists($Title) Then
WinActivate($Title, "")
;ControlFocus($Title, "", $Class)
$var = ControlGetText($Title, "", $Class)
;MsgBox(0, $Class & " Text", $ButText)
;MsgBox(0, $Class & " Text", $var)
If StringInStr($var, $ButText) Then ControlClick($Title, "", $Class)
Else
;MsgBox(0, $Title, "Window DOESN'T exists")
EndIf
EndFuncThanks