Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Get the list of Warcraft III windows as an Array
- warcraftWindows := GetWarcraftWindows()
- Loop
- {
- ; Loop through each Warcraft III window
- for index, winID in warcraftWindows
- {
- ; Activate the current Warcraft III window
- Sleep, 1000 ; Wait before switching windows
- WinActivate, ahk_id %winID%
- WinWaitActive, ahk_id %winID%
- Sleep, 2000 ; Ensure window is fully active
- ; Record the current latest file in the folder
- prevLatestFile := GetLatestFile("D:\screenshots")
- ; Take screenshot of the active window
- Send, {Alt down}{PrintScreen}{Alt up}
- Sleep, 1000
- Send, {Enter}-quest{Enter} ; Execute -quest after screenshot
- ; Wait for screenshot processing (increase sleep if needed)
- Sleep, 2000
- ; Wait until a new file (new screenshot) is detected
- latestFile := prevLatestFile
- newTimeout := A_TickCount + 5000 ; Try up to 5 seconds
- while (A_TickCount < newTimeout && latestFile = prevLatestFile)
- {
- Sleep, 500
- latestFile := GetLatestFile("D:\screenshots")
- }
- ; OCR recognition using Tesseract on the new screenshot
- OutputTextPath := "D:\screenshots\output_text"
- RunWait, tesseract.exe %latestFile% %OutputTextPath%, , Hide
- ; Read text from the OCR output file
- OutputTextPath := "D:\screenshots\output_text.txt"
- FileRead, outputText, %OutputTextPath%
- ; Search for six digits with spaces around them
- RegExMatch(outputText, "[\s\-_—](\d{6})\s\(", match)
- if (match1)
- {
- Send, {Enter}-afk %match1%{Enter}
- ; Add code into log-file
- FileAppend, -afk %match1%`n, D:\screenshots\afk_codes.txt
- ; Additional commands after found afk code
- Sleep, 1000
- Send, {Enter}-greed{Enter}
- Sleep, 1000
- Send, {Enter}-str{Enter}
- Sleep, 1000
- Send, {Enter}-save{Enter}
- Sleep, 1000
- Send, {Enter}-clear{Enter}
- }
- }
- ; Wait before starting the next cycle
- Sleep, 2000
- }
- GetWarcraftWindows()
- {
- warcraftWindows := Array() ; Use an Array instead of a List
- WinGet, idList, List, Warcraft III
- Loop, %idList%
- {
- winID := idList%A_Index%
- warcraftWindows.Push(winID)
- }
- return warcraftWindows
- }
- GetLatestFile(folderPath)
- {
- latestFile := ""
- latestTime := 0
- Loop, Files, %folderPath%\*.png
- {
- if (A_LoopFileTimeModified > latestTime)
- {
- latestTime := A_LoopFileTimeModified
- latestFile := A_LoopFileFullPath
- }
- }
- return latestFile
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement