Jump to content

Timer, on an event


Recommended Posts

At least I got the idea.

Could I ask a tangent on this,,,

I would like to time the time it takes from the "Run" command to the WinWaitActive("Mozilla Firefox")

Lemme give it a shot:

If WinExists("Program","") Then $Timer=TimerInit()

Do

Sleep(1)

Run("Program.exe")

Until Not WinExists(Mozilla Firefox","")

Msgbox(0,"Execute Time",TimerDiff($Timer))

Is that the jist of it?

Why do you Sleep it?

Link to comment
Share on other sites

Thanks, gen. I was thinking of using this code from the help file

#include <GUIConstants.au3>
#include <Date.au3>
HotKeySet("{PAUSE}", "Togglepause")
opt("TrayIconDebug",1)
Global $Secs, $Mins, $Hour, $Time, $Paused
;Create GUI
GUICreate("Timer",120, 50)
GUICtrlCreateLabel("00:00:00", 10,10)
GUISetState()
;Start timer
$timer = TimerInit()
AdlibEnable("Timer", 50)
;
While 1
 
  $msg = GUIGetMsg()
;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
  Select
     Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect
Wend
;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused 
        sleep(100)
          WEnd
      EndFunc
      
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)
        ControlSetText("Timer", "", "Static1", $Time)
      EndFunc;==>Timer

I tried messing around with it, so that when firefox closed it would freeze the timer. No luck, it either didn't freeze or just closed firefox.

Any ideas on how to get it to stop the timer when firefox closes?

Edited by Delta01
Link to comment
Share on other sites

You are overthinking this.

$stamp = TimerInit()
Run("Firefox.exe")
WinWaitActive("Firefox")
$diff = TimerDiff($stamp)

MsgBox(0,"","Firefox took " & $diff / 1000 & " seconds to execute")oÝ÷ ØÊ+^r'âq©eÉ«­¢+ØÀÌØíÍѵÀôQ¥µÉ%¹¥Ð ¤)IÕ¸ ÅÕ½ÐíèÀäÈíAɽɴ¥±ÌÀäÈí5½é¥±±¥É½àÀäÈí¥É½à¹áÅÕ½Ðì¤)]¥¹]¥ÑÑ¥Ù ÅÕ½Ðí5½é¥±±¥É½àÅÕ½Ðì¤(ÀÌØí¥ôQ¥µÉ¥ ÀÌØíÍѵÀ¤()5Í  ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥É½àѽ½¬ÅÕ½ÐìµÀìÀÌØí¥¼ÄÀÀÀµÀìÅÕ½Ðìͽ¹ÌѼáÕÑÅÕ½Ðì¤
Edited by weaponx
Link to comment
Share on other sites

Did you expect a different result? You didn't say Firefox would already be open. If Firefox has a default homepage set use that as the window title. If there is no default page set then you will have to change the WinTitle match mode to only look for Mozilla Firefox instead of any title containing *Mozilla Firefox*.

Google is my homepage. This will truncate return time to 2 decimal digits.

$stamp = TimerInit()
Run("C:\Program Files\Mozilla Firefox\firefox.exe")
WinWaitActive("Google - Mozilla Firefox")
$diff = TimerDiff($stamp)

MsgBox(0,"","Firefox took " & StringFormat("%.2f", $diff / 1000) & " seconds to execute")
Edited by weaponx
Link to comment
Share on other sites

Did you expect a different result? You didn't say Firefox would already be open. If Firefox has a default homepage set use that as the window title. If there is no default page set then you will have to change the WinTitle match mode to only look for Mozilla Firefox instead of any title containing *Mozilla Firefox*.

Google is my homepage. This will truncate return time to 2 decimal digits.

$stamp = TimerInit()
Run("C:\Program Files\Mozilla Firefox\firefox.exe")
WinWaitActive("Google - Mozilla Firefox")
$diff = TimerDiff($stamp)

MsgBox(0,"","Firefox took " & StringFormat("%.2f", $diff / 1000) & " seconds to execute")
Thanks, it works
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...