Jump to content

start a test then use an autoit stopwatch to time taken


st4vr0s
 Share

Recommended Posts

Hi,

I'm trying to open a program start it running time it with a stopwatch, pause on an event then wait for it to finish.

I can do the start to end no problem but what I want to be able to do is start the onscreen stopwatch like the "_TicksToTime.au3" in the help file, pause the stopwatch on a triger of another event say for example a window opening, then PRINTSCREEN close the stopwatch program and then the app that I was timing?

Can I add something to the code below to monitor an event such as a new window, or do I need different code

Thanks

; *** Demo to show a timer window
#include <GUIConstantsEx.au3>
#include <Date.au3>
Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)
Global $timer, $Secs, $Mins, $Hour, $Time
_Main()
Func _Main()
;Create GUI
GUICreate("Timer", 120, 50)
GUICtrlCreateLabel("00:00:00", 10, 10)
GUISetState()
;Start timer
$timer = TimerInit()
AdlibRegister("Timer", 50)
;
While 1
  ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")
  Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    Exit
  EndSwitch
  ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
WEnd
EndFunc   ;==>_Main
;
Func Timer()
_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
Local $sTime = $Time  ; save current time to be able to test and avoid flicker..
$Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time)
EndFunc   ;==>Timer
Link to comment
Share on other sites

Somethings wrong:

The script hangs at line 72 - Endswitch

MouseClick ("left",61,243,1,20)
Winwait ("Encode Queue","Video:")
; *** Demo to show a timer window
#include <GUIConstantsEx.au3>
#include <Date.au3>
Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)
Global $timer, $Secs, $Mins, $Hour, $Time
_Main()
Func _Main()
;Create GUI
GUICreate("Timer", 240, 100)
GUICtrlCreateLabel("00:00:00", 20, 20)
GUISetState()
;Start timer
$timer = TimerInit()
AdlibRegister("Timer", 50)
;
While 1
  ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")
  Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    Exit
  EndSwitch
  ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
WEnd
EndFunc   ;==>_Main
;
Func Timer()
_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
Local $sTime = $Time  ; save current time to be able to test and avoid flicker..
$Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time)
EndFunc   ;==>Timer

WinWaitActive ("Encode Queue","Video")
if not WinActive ("Encode Queue","Video") Then Send ("{PRINTSCREEN}")

I cant think of a way to pause the timer after the "visible" text has disappeared. So I thought maybe I could printscreen the timer on its own bot then I need ot stope the timer.

Any advice welcome to a beginner :)

Thanks

Link to comment
Share on other sites

The script isn't hanging, it's just looping through the While...Wend loop.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks for that. I'm getting there in the end :)

So I'm getting towards the end of my script now but i was wondering if its possible to do teh following....

When the test runs the window title stays the same from start to end but the visible text changes. Is it possible to say something like wait for "this text" to appear in "this window" then when "this visibile" text disappears move to the next line?

Link to comment
Share on other sites

See WinGetText() and StringInStr(). Both are in the help file.

If StringInStr(WinGetText("Some Window", "Text to watch for")) Then
    ;;do whatever
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks for the info, will give that a go.

I ended up having to use

While PixelGetColor(127, 243) = 0x90C161

WEnd
Dim $text
If PixelGetColor(126,244) = 0x3D3D3D Then
$text = WinGetText("Timer", "")
SplashTextOn ( "Test Result", "Time to complete Handbrake Benchmark:"& $text,400,150,10,410,0,"",26,"")
WinWait ("Test Result")
if not WinActive ("Test Result") then WinActivate ("Test Result")
WinWaitActive ("Test Result")

Which is a little crude but works.

Will try your way later.

Thanks

Link to comment
Share on other sites

See WinGetText() and StringInStr(). Both are in the help file.

If StringInStr(WinGetText("Some Window", "Text to watch for")) Then
    ;;do whatever
EndIf

I've managed to try this and it works when its looking for the text but what do I need to change so that it runs and action when the text disappears?

If StringInStr(WinGetText("Benchmark",""),"Welcome to the benchmark") Then
MsgBox (64,"Success","It workds")
Endif

So now I want to write it so that when the "Welcome to the benchmark") disappears it runs the next action but I'm unsure what to use.

EDIT: Just to add.....the window title stays the visible text changes

Thanks

Edited by st4vr0s
Link to comment
Share on other sites

I thought you wanted to run the next action when new text showed up in the window.

How many windows are going to be involved where you have a text change?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...