JustinM Posted October 21, 2016 Share Posted October 21, 2016 How can I set my pixel search to wait until it finds what it needs without finishing the script? I'm trying to do a loop but my skills aren't that good. Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode",2) MouseMove(475,275,1) $pixel = PixelSearch(19,12,494,495, 0x22EFB8) If IsArray($pixel) = True Then Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") ElseIf IsArray($pixel) = False Then ;How Can I loop this to go back to the begining of the IF IsArray($pixel) = True Then statement? EndIf Link to comment Share on other sites More sharing options...
Gianni Posted October 21, 2016 Share Posted October 21, 2016 yu could use Do ... Until instead of If ... Then Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode", 2) MouseMove(475, 275, 1) Do Sleep(1000) $pixel = PixelSearch(19, 12, 494, 495, 0x22EFB8) Until IsArray($pixel) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
kcvinu Posted October 21, 2016 Share Posted October 21, 2016 (edited) Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode",2) MouseMove(475,275,1) While 1 $pixel = PixelSearch(19,12,494,495, 0x22EFB8) If IsArray($pixel) = True Then Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") ElseIf IsArray($pixel) = False Then ContinueLoop ;How Can I loop this to go back to the begining of the IF IsArray($pixel) = True Then statement? EndIf Wend Edited October 21, 2016 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
JustinM Posted October 21, 2016 Author Share Posted October 21, 2016 31 minutes ago, Chimp said: yu could use Do ... Until instead of If ... Then Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode", 2) MouseMove(475, 275, 1) Do Sleep(1000) $pixel = PixelSearch(19, 12, 494, 495, 0x22EFB8) Until IsArray($pixel) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") I tried using this, but it took the SS at the wrong time. It went off during the benchmark. 32 minutes ago, kcvinu said: Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode",2) MouseMove(475,275,1) While 1 $pixel = PixelSearch(19,12,494,495, 0x22EFB8) If IsArray($pixel) = True Then Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") ElseIf IsArray($pixel) = False Then ContinueLoop ;How Can I loop this to go back to the begining of the IF IsArray($pixel) = True Then statement? EndIf Wend Doing it this way made the script loop and wouldn't end, and it didn't take a SS. What else could I try? Link to comment Share on other sites More sharing options...
232showtime Posted October 22, 2016 Share Posted October 22, 2016 Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode",2) MouseMove(475,275,1) While 1 $pixel = PixelSearch(19,12,494,495, 0x22EFB8) If IsArray($pixel) = True Then Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") EndIf Wend ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
JustinM Posted October 24, 2016 Author Share Posted October 24, 2016 On 10/22/2016 at 2:12 AM, 232showtime said: Run("AS SSD Benchmark") WinWait("AS SSD Benchmark 1.9.5986.35387") WinActivate("AS SSD Benchmark 1.9.5986.35387") Sleep(1000) Send("{ENTER}") AutoItSetOption("MouseCoordMode",2) MouseMove(475,275,1) While 1 $pixel = PixelSearch(19,12,494,495, 0x22EFB8) If IsArray($pixel) = True Then Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\Desktop\AS_SSD.jpg", "AS SSD Benchmark 1.9.5986.35387") EndIf Wend This does not work. It just loops, it will never take the Screen Shot Link to comment Share on other sites More sharing options...
232showtime Posted October 24, 2016 Share Posted October 24, 2016 (edited) I haven't tested that code, just a guess based from your script, I created new working script for testing, and its working fine... #include <ScreenCapture.au3> HotKeySet("{ESC}", "Quit") ;~ Run("AS SSD Benchmark") ;~ WinWait("AS SSD Benchmark 1.9.5986.35387") ;~ WinActivate("AS SSD Benchmark 1.9.5986.35387") ;~ Sleep(1000) ;~ Send("{ENTER}") ;~ AutoItSetOption("MouseCoordMode", 2) ;~ MouseMove(475, 275, 1) While 1 $pixel = PixelSearch(19, 12, 494, 495, 0x0A246A) If IsArray($pixel) = True Then ;~ Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\AS_SSD.jpg", "[CLASS:CabinetWClass]") MsgBox(64, "Success!!!", "Pixel found!!!") ShellExecute("C:\Users\Public\AS_SSD.jpg") Exit Else MsgBox(16, "Error!!!", "Pixel not found!!!") Exit EndIf WEnd Func Quit() Exit EndFunc ;==>Quit Edited October 24, 2016 by 232showtime edit: why do you want to automate AS SSD Benchmark 1.9.5986.35387??? ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
JustinM Posted October 24, 2016 Author Share Posted October 24, 2016 16 minutes ago, 232showtime said: I haven't tested that code, just a guess based from your script, I created new working script for testing, and its working fine... #include <ScreenCapture.au3> HotKeySet("{ESC}", "Quit") ;~ Run("AS SSD Benchmark") ;~ WinWait("AS SSD Benchmark 1.9.5986.35387") ;~ WinActivate("AS SSD Benchmark 1.9.5986.35387") ;~ Sleep(1000) ;~ Send("{ENTER}") ;~ AutoItSetOption("MouseCoordMode", 2) ;~ MouseMove(475, 275, 1) While 1 $pixel = PixelSearch(19, 12, 494, 495, 0x0A246A) If IsArray($pixel) = True Then ;~ Sleep(10000) _ScreenCapture_CaptureWnd("C:\Users\Public\AS_SSD.jpg", "[CLASS:CabinetWClass]") MsgBox(64, "Success!!!", "Pixel found!!!") ShellExecute("C:\Users\Public\AS_SSD.jpg") Exit Else MsgBox(16, "Error!!!", "Pixel not found!!!") Exit EndIf WEnd Func Quit() Exit EndFunc ;==>Quit Idk why mine is failing, the mouse is not moving, and the color code is correct where the mouse is moving -- my msg box comes up saying it cannot find the pixel Run(AS SSD Benchmark) WinWait(AS SSD Benchmark 1.9.5986.35387) WinActivate(AS SSD Benchmark 1.9.5986.35387) Sleep(1000) Send({ENTER}) AutoItSetOption(MouseCoordMode,2) MouseMove(475,285,1) Sleep(2000) #cs While 1 $pixel = PixelSearch(19,12,480,320, 0x10CB99) If IsArray($pixel) = True Then Sleep(1000) _ScreenCapture_CaptureWnd(CUsersPublicDesktopAS_SSD.jpg, AS SSD Benchmark 1.9.5986.35387) EndIf WEnd EndIf #ce While 1 $pixel = PixelSearch(19,12,480,320, 0x10CB99) If IsArray($pixel) = True Then Sleep(1000) _ScreenCapture_CaptureWnd(CUsersPublicDesktopAS_SSD.jpg, AS SSD Benchmark 1.9.5986.35387) MsgBox(64, Succ, pixel found) Exit Else MsgBox(64, Fail, no pixel found) Exit EndIf WEnd Link to comment Share on other sites More sharing options...
JustinM Posted October 26, 2016 Author Share Posted October 26, 2016 Is any one able to help me? Link to comment Share on other sites More sharing options...
MuffinMan Posted October 26, 2016 Share Posted October 26, 2016 So did 232Showtime's code not work for you? I looked at the last code you posted and it has lots of syntax errors; maybe you stripped out all of the double-quotes somehow? Link to comment Share on other sites More sharing options...
Danyfirex Posted October 26, 2016 Share Posted October 26, 2016 You can handle that based in window control text. You can do something like this. #include <WinAPI.au3> #include <ScreenCapture.au3> Local $sASSSDBenchmarkTitle = "AS SSD Benchmark 1.9.5986.35387" Local $sASSSDBenchmarkFullPath = "AS SSD Benchmark.exe" ShellExecute($sASSSDBenchmarkFullPath) Local $hWindow = WinWaitActive($sASSSDBenchmarkTitle) ControlClick($hWindow, "", _MakeNetClassNN($hWindow, "BUTTON", "6")) Local $sText = "" While Sleep(30) $sText = ControlGetText($hWindow, "", _MakeNetClassNN($hWindow, "STATIC", "21")) If Not WinExists($sASSSDBenchmarkTitle) Then Exit MsgBox(64, "Error", "Cant Find AS SSD Benchmark window. bye bye") $sText = StringReplace($sText, ",", ".") If $sText <> "0.000 ms" Then _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sText & ".jpg", "AS SSD Benchmark 1.9.5986.35387") MsgBox(64, "Success!!!", "Text Found!!!") ShellExecute(@ScriptDir & "\" & $sText & ".jpg") ExitLoop EndIf WEnd Func _MakeNetClassNN($hwnd, $sControlType, $sIndexNN) Local $sStringClass = _WinAPI_GetClassName($hwnd) Local $sStringWin = StringMid($sStringClass, 1, StringInStr($sStringClass, ".")) Return $sStringWin & $sControlType & StringMid($sStringClass, StringInStr($sStringClass, ".app")) & $sIndexNN EndFunc ;==>_MakeNetClassNN Saludos Alamin 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
JustinM Posted October 27, 2016 Author Share Posted October 27, 2016 19 hours ago, MuffinMan said: So did 232Showtime's code not work for you? I looked at the last code you posted and it has lots of syntax errors; maybe you stripped out all of the double-quotes somehow? I ran the code I provided and the msg box fail, no pixel found popped up But why though? the pixel is clearly there 18 hours ago, Danyfirex said: You can handle that based in window control text. You can do something like this. #include <WinAPI.au3> #include <ScreenCapture.au3> Local $sASSSDBenchmarkTitle = "AS SSD Benchmark 1.9.5986.35387" Local $sASSSDBenchmarkFullPath = "AS SSD Benchmark.exe" ShellExecute($sASSSDBenchmarkFullPath) Local $hWindow = WinWaitActive($sASSSDBenchmarkTitle) ControlClick($hWindow, "", _MakeNetClassNN($hWindow, "BUTTON", "6")) Local $sText = "" While Sleep(30) $sText = ControlGetText($hWindow, "", _MakeNetClassNN($hWindow, "STATIC", "21")) If Not WinExists($sASSSDBenchmarkTitle) Then Exit MsgBox(64, "Error", "Cant Find AS SSD Benchmark window. bye bye") $sText = StringReplace($sText, ",", ".") If $sText <> "0.000 ms" Then _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sText & ".jpg", "AS SSD Benchmark 1.9.5986.35387") MsgBox(64, "Success!!!", "Text Found!!!") ShellExecute(@ScriptDir & "\" & $sText & ".jpg") ExitLoop EndIf WEnd Func _MakeNetClassNN($hwnd, $sControlType, $sIndexNN) Local $sStringClass = _WinAPI_GetClassName($hwnd) Local $sStringWin = StringMid($sStringClass, 1, StringInStr($sStringClass, ".")) Return $sStringWin & $sControlType & StringMid($sStringClass, StringInStr($sStringClass, ".app")) & $sIndexNN EndFunc ;==>_MakeNetClassNN Saludos This looks so confusing to me (I know the basics) but I will give it a shot Link to comment Share on other sites More sharing options...
JustinM Posted October 27, 2016 Author Share Posted October 27, 2016 19 hours ago, Danyfirex said: You can handle that based in window control text. You can do something like this. #include <WinAPI.au3> #include <ScreenCapture.au3> Local $sASSSDBenchmarkTitle = "AS SSD Benchmark 1.9.5986.35387" Local $sASSSDBenchmarkFullPath = "AS SSD Benchmark.exe" ShellExecute($sASSSDBenchmarkFullPath) Local $hWindow = WinWaitActive($sASSSDBenchmarkTitle) ControlClick($hWindow, "", _MakeNetClassNN($hWindow, "BUTTON", "6")) Local $sText = "" While Sleep(30) $sText = ControlGetText($hWindow, "", _MakeNetClassNN($hWindow, "STATIC", "21")) If Not WinExists($sASSSDBenchmarkTitle) Then Exit MsgBox(64, "Error", "Cant Find AS SSD Benchmark window. bye bye") $sText = StringReplace($sText, ",", ".") If $sText <> "0.000 ms" Then _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sText & ".jpg", "AS SSD Benchmark 1.9.5986.35387") MsgBox(64, "Success!!!", "Text Found!!!") ShellExecute(@ScriptDir & "\" & $sText & ".jpg") ExitLoop EndIf WEnd Func _MakeNetClassNN($hwnd, $sControlType, $sIndexNN) Local $sStringClass = _WinAPI_GetClassName($hwnd) Local $sStringWin = StringMid($sStringClass, 1, StringInStr($sStringClass, ".")) Return $sStringWin & $sControlType & StringMid($sStringClass, StringInStr($sStringClass, ".app")) & $sIndexNN EndFunc ;==>_MakeNetClassNN Saludos Is there a way to have it take the screen shot only after the whole benchmark has ran? I ran the script and it immediately takes the ss. The time this benchmark takes depends on the hard drive installed Link to comment Share on other sites More sharing options...
Danyfirex Posted October 27, 2016 Share Posted October 27, 2016 when benchmark ends? when text appears in the picture you put above (the one with the red mark)? Tthe code I posted work that way. It should wait till text is diferent to "0.000 ms" or does the app show diferent default text? Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
JustinM Posted October 27, 2016 Author Share Posted October 27, 2016 5 minutes ago, Danyfirex said: when benchmark ends? when text appears in the picture you put above (the one with the red mark)? Tthe code I posted work that way. It should wait till text is diferent to "0.000 ms" or does the app show diferent default text? Saludos This is how the benchmark is when you first open it, do I change 0.000 ms to 0.00 ms? Link to comment Share on other sites More sharing options...
JustinM Posted October 27, 2016 Author Share Posted October 27, 2016 Just now, JustinM said: This is how the benchmark is when you first open it, do I change 0.000 ms to 0.00 ms? and this is how it looks as soon as you press start Link to comment Share on other sites More sharing options...
Danyfirex Posted October 27, 2016 Share Posted October 27, 2016 I meant before press Click in start how this button text look like? PD: Don't quoted me each time. just write in the topic. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Danyfirex Posted October 27, 2016 Share Posted October 27, 2016 try this version. #RequireAdmin #include <WinAPI.au3> #include <ScreenCapture.au3> Local $sASSSDBenchmarkTitle = "AS SSD Benchmark 1.9.5986.35387" Local $sASSSDBenchmarkFullPath = "AS SSD Benchmark.exe" ShellExecute($sASSSDBenchmarkFullPath) Local $hWindow = WinWaitActive($sASSSDBenchmarkTitle,"",5) If not $hWindow Then Exit ;Exit If No Find Window ControlClick($hWindow, "", _MakeNetClassNN($hWindow, "BUTTON", "6")) Sleep(1000) ;Just Wait For Benchmark Starts Local $sText = "" While Sleep(30) $sText = ControlGetText($hWindow, "", _MakeNetClassNN($hWindow, "STATIC", "21")) If Not WinExists($sASSSDBenchmarkTitle) Then Exit MsgBox(64, "Error", "Cant Find AS SSD Benchmark window. bye bye") $sText = StringReplace($sText, ",", ".") ;~ ConsoleWrite('"' & $sText & '"' & @CRLF) If $sText <> "0.000 ms" Then _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sText & ".jpg", "AS SSD Benchmark 1.9.5986.35387") MsgBox(64, "Success!!!", "Text Found!!!") ShellExecute(@ScriptDir & "\" & $sText & ".jpg") ExitLoop EndIf WEnd Func _MakeNetClassNN($hwnd, $sControlType, $sIndexNN) Local $sStringClass = _WinAPI_GetClassName($hwnd) Local $sStringWin = StringMid($sStringClass, 1, StringInStr($sStringClass, ".")) Return $sStringWin & $sControlType & StringMid($sStringClass, StringInStr($sStringClass, ".app")) & $sIndexNN EndFunc ;==>_MakeNetClassNN Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
JustinM Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) @Danyfirex This works perfectly! I hope you don't mind but can you please explain it? How did you know to use "_MakeNetClassNN? What does the "" mean for $sText = ""? What is the Func's purpose that you made? Edited October 27, 2016 by JustinM Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted October 27, 2016 Share Posted October 27, 2016 (edited) I would shy away from pixel functions and try to use more controllable parameters. This is working for me to loop it and take screen shots of each test session. #RequireAdmin #include <ScreenCapture.au3> $sTitle = "AS SSD Benchmark 1.9.5986.35387" $sBinary = "AS SSD Benchmark.exe" $StartButton = "[CLASS:WindowsForms10.BUTTON.app.0.141b42a_r10_ad1; INSTANCE:6]" $iExitAfter = 5 ;Run this many times and then Exit $iLoopNum = 0 ShellExecute($sBinary) ;Launch program from script directory Sleep(2000) ;One time wait for program to load if static time is a problem create a loop to wait While 1 If WinExists($sTitle, "") Then Sleep(100) Else Exit ;If Program Window is not found exit EndIf If NOT ControlCommand($sTitle, "", $StartButton, "IsEnabled") Then ContinueLoop If $iLoopNum <> 0 Then _ScreenCapture_CaptureWnd(@DesktopCommonDir & "\AS_SSD" & $iLoopNum & ".jpg", $sTitle) $iLoopNum = $iLoopNum +1 If $iLoopNum = $iExitAfter Then ProcessClose($sBinary) ;Exit after # of loops completed ;MsgBox(0, "", "Restarting Bench") WinActivate($sTitle, "") ControlClick($sTitle, "Start", $StartButton) Sleep(100) WEnd Edited October 27, 2016 by ViciousXUSMC Link to comment Share on other sites More sharing options...
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