manit Posted September 1 Posted September 1 hi , I am using autoit for clicking in audacity application Here is relevant part of code #include <MsgBoxConstants.au3> #include <Date.au3> AutoItSetOption("SendKeyDelay",500) Local $TextFileName = "Log.txt" $Logging = "Hello at " & _NowDate() & ' ' & _NowTime() &@CRLF FileWrite($TextFileName, $Logging) Local $pythonplayvividh=Run(@ComSpec & " /c " & "python play-vb-in-browser.txt") Sleep(10000) Local $prev_audacity_handle = WinWait("Audacity","",10) If $prev_audacity_handle == 0 Then ; Do $Logging = "Opening audacity application" &@CRLF FileWrite($TextFileName, $Logging) Local $iPID = Run("c:\Program Files\Audacity\audacity.exe", "", @SW_SHOWMAXIMIZED) Local $audacity_handle = WinWait("Audacity","",100) ;MsgBox($MB_SYSTEMMODAL, "Script_Info", "window with title audacity is " & $audacity_handle) Until $audacity_handle <> 0 Else $Logging = "Audacity application was already open" &@CRLF FileWrite($TextFileName, $Logging) EndIf If WinExists("Automatic Crash Recovery") Then Local $audacity_crash_handle = WinWait("Automatic Crash Recovery","",10) WinActivate($audacity_crash_handle) ControlClick($audacity_crash_handle, "", "[CLASS:Button; INSTANCE:5]");skipping not discarding selected $Logging = "Audacity crash window found and discard selected" &@CRLF FileWrite($TextFileName, $Logging) ;Send("{TAB}") ;Send("{SPACE}") Else $Logging = "Audacity crash window not found" &@CRLF FileWrite($TextFileName, $Logging) EndIf Here is content of log.txt Quote Hello at 28-08-2025 16:54:52 Opening audacity application Audacity crash window not found Audacity window found Here is the autoit window info tool analysis Also attached the window which i want to detect Please suggest - what I am doing wrong ? Thanks.
ioa747 Posted September 1 Posted September 1 in log.txt it says 'Audacity window found' which means it passed the "Automatic Crash Recovery" checkpoint and hasn't crashed yet the question is what happens below there is a loop that checks again if Audacity Crash what happens after the 'Audacity window found' point? I know that I know nothing
Nine Posted September 1 Posted September 1 7 hours ago, manit said: Please suggest - what I am doing wrong ? Either the window is not shown yet when you check for it (which make sense since you do not wait between starting the app and checking for "Automatic Crash Recovery") Or "Automatic Crash Recovery" contains special character (like hard space) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
manit Posted September 15 Author Posted September 15 (edited) I ran the script with "Audacity " and "Automatic Crash Recovery" window open. Still got same error. Considering possibility of hard space , what can I do ? Edited September 15 by manit
ioa747 Posted September 15 Posted September 15 try this expandcollapse popup; https://www.autoitscript.com/forum/topic/213106-autoit-not-detecting-window/#findComment-1545666 #include <MsgBoxConstants.au3> #include <Date.au3> AutoItSetOption("SendKeyDelay", 500) Main() ;--------------------------------------------------------------------------------------- Func Main() Logging("Hello at " & _NowDate() & ' ' & _NowTime() & @CRLF) ;~ PythonPlayvividh(@ScriptDir & "\play-vb-in-browser.txt") Local $audacity_handle = OpenAudacity() ConsoleWrite("- $audacity_handle=" & $audacity_handle & @CRLF) CrashRecovery() Local $sTempo = ControlGetText($audacity_handle, "", "Edit2") ConsoleWrite("- $sTempo=" & $sTempo & @CRLF) EndFunc ;==>Main ;--------------------------------------------------------------------------------------- Func PythonPlayvividh($sFilePath) Local $iPID = Run(@ComSpec & ' /c python "' & $sFilePath & '"') ProcessWaitClose($iPID) ; Wait until the process has closed. EndFunc ;==>PythonPlayvividh Func OpenAudacity($iTimeout = 10000) Local $sAudacityPath = "c:\Program Files\Audacity\audacity.exe" ; "C:\Program Files\Audacity" If Not FileExists($sAudacityPath) Then Logging("OpenAudacity: Couldn't find the application path:" & $sAudacityPath & @CRLF) Exit EndIf Local $sAudacityDir = StringLeft($sAudacityPath, StringInStr($sAudacityPath, "\", $STR_NOCASESENSEBASIC, -1) - 1) Local $audacity_handle = 0 If WinExists("Audacity") Then $audacity_handle = WinWait("Audacity", "", 5) Logging("OpenAudacity: Audacity application was already open, HW:" & $audacity_handle & @CRLF) Else Logging("OpenAudacity: Opening audacity application" & @CRLF) Run($sAudacityPath, $sAudacityDir, @SW_MAXIMIZE) $audacity_handle = WinWait("Audacity", "", 5) Logging("OpenAudacity: Audacity starting HW:" & $audacity_handle & @CRLF) Local $iStartTime = TimerInit() While WinExists($audacity_handle) If TimerDiff($iStartTime) > $iTimeout Then ExitLoop Sleep(100) WEnd $audacity_handle = WinWait("Audacity", "", 5) If Not IsHWnd($audacity_handle) Then Logging("OpenAudacity: Couldn't find the Audacity window" & @CRLF) Exit EndIf Logging("OpenAudacity: Audacity Final HW:" & $audacity_handle & @CRLF) EndIf Return $audacity_handle EndFunc ;==>OpenAudacity Func CrashRecovery() If Not WinExists("Automatic Crash Recovery") Then Return Logging("CrashRecovery: Audacity crash window found" & @CRLF) Local $audacity_crash_handle = WinWait("Automatic Crash Recovery", "", 5) WinActivate($audacity_crash_handle) Local $iskipping = ControlClick($audacity_crash_handle, "", "[CLASS:Button; INSTANCE:5]") ;skipping not discarding selected Logging("CrashRecovery: ... and 'Skip' selected:" & $iskipping & @CRLF) EndFunc ;==>CrashRecovery Func Logging($sMsg, $iSLno = @ScriptLineNumber) Local Static $sLogFile = @ScriptDir & "\Log.txt" ConsoleWrite("(" & $iSLno & ") " & $sMsg) If StringLeft($sMsg, 8) = "Hello at" Then $sMsg = @CRLF & $sMsg Else $sMsg = @TAB & $sMsg EndIf FileWrite($sLogFile, $sMsg) EndFunc ;==>Logging I know that I know nothing
Nine Posted September 15 Posted September 15 (edited) To check the exact content of a string (window title), use the following : Sleep(5000) ; make sure Automatic Crash Recovery window is the top-most active window Local $sTitle = WinGetTitle("[ACTIVE]") ConsoleWrite($sTitle & @CRLF) $sTitle = DisplayString($sTitle) ConsoleWrite($sTitle & @CRLF) Func DisplayString($sString) Local $iSize = StringLen($sString) Local $tBuffer = DllStructCreate("byte data[" & $iSize & "]") $tBuffer.data = Binary($sString) Return _WinAPI_CryptBinaryToString($tBuffer, $iSize) EndFunc ;==>DisplayString Func _WinAPI_CryptBinaryToString($tBuffer, $iSize, $iFlags = 4) Local $aRet = DllCall("Crypt32.dll", "bool", "CryptBinaryToString", "struct*", $tBuffer, "dword", $iSize, _ "dword", $iFlags, "struct*", 0, "dword*", 0) Local $tBuffer2 = DllStructCreate("char hex[" & $aRet[5] & "]") DllCall("Crypt32.dll", "bool", "CryptBinaryToString", "struct*", $tBuffer, "dword", $iSize, _ "dword", $iFlags, "struct*", $tBuffer2, "dword*", $aRet[5]) Return $tBuffer2.hex EndFunc ;==>_WinAPI_CryptBinaryToString Edited September 15 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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