Jump to content
Sign in to follow this  
Delta01

Timer, on an event

Recommended Posts

Delta01

Hi

I can't figure out how to stop a timer on an event. For example, If Mozilla Firefox opens, have the timer start then and when it closes have it stop then.

Any help would be appreciated :)

Thanks

Share this post


Link to post
Share on other sites
Generator

If WinExists("Mozilla Firefox","") Then $Timer=TimerInit()

Do

Sleep(1)

Until Not WinExists(Mozilla Firefox","")

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

You get the idea

Share this post


Link to post
Share on other sites
westsan

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?

Share this post


Link to post
Share on other sites
Delta01

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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Delta01

weaponx, that code doesn't work. If firefox is open the msg box just appears instantly with a number like 2.5737383838.

Any other ideas and how can i take away the numbers after a decimal point?

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Delta01

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

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.