JustinM

If Then Help

21 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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")

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by kcvinu

My Contributions

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)

 

Share this post


Link to post
Share on other sites
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? 

Share this post


Link to post
Share on other sites
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 graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 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 graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
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

 

color.PNG

Share this post


Link to post
Share on other sites

Is any one able to help me?

Share this post


Link to post
Share on other sites

#10 ·  Posted

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?

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted

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 :o 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

Share this post


Link to post
Share on other sites

#13 ·  Posted

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

Share this post


Link to post
Share on other sites

#14 ·  Posted

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

Share this post


Link to post
Share on other sites

#15 ·  Posted

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?

ss.PNG

Share this post


Link to post
Share on other sites

#16 ·  Posted

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?

ss.PNG

and this is how it looks as soon as you press start

ss2.PNG

Share this post


Link to post
Share on other sites

#17 ·  Posted

I meant before press Click in start how this button text look like?

7d1ff0ab6bbf48f88615c77b12ab41ca.png

 

 

PD: Don't quoted me each time. just write in the topic.

Saludos

Share this post


Link to post
Share on other sites

#18 ·  Posted

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

Share this post


Link to post
Share on other sites

#19 ·  Posted (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 by JustinM

Share this post


Link to post
Share on other sites

#20 ·  Posted (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 by ViciousXUSMC

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now