Delta01 Posted August 22, 2007 Posted August 22, 2007 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
Generator Posted August 22, 2007 Posted August 22, 2007 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
westsan Posted August 22, 2007 Posted August 22, 2007 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?
Delta01 Posted August 22, 2007 Author Posted August 22, 2007 (edited) Thanks, gen. I was thinking of using this code from the help file expandcollapse popup#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 August 22, 2007 by Delta01
weaponx Posted August 22, 2007 Posted August 22, 2007 (edited) You are overthinking this. $stamp = TimerInit() Run("Firefox.exe") WinWaitActive("Firefox") $diff = TimerDiff($stamp) MsgBox(0,"","Firefox took " & $diff / 1000 & " seconds to execute")oÝ÷ ØÊ+zÊ^r'âq©eÉ«¢+ØÀÌØíÍѵÀôQ¥µÉ%¹¥Ð ¤)IÕ¸ ÅÕ½ÐíèÀäÈíAɽɴ¥±ÌÀäÈí5½é¥±±¥É½àÀäÈí¥É½à¹áÅÕ½Ðì¤)]¥¹]¥ÑÑ¥Ù ÅÕ½Ðí5½é¥±±¥É½àÅÕ½Ðì¤(ÀÌØí¥ôQ¥µÉ¥ ÀÌØíÍѵÀ¤()5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥É½àѽ½¬ÅÕ½ÐìµÀìÀÌØí¥¼ÄÀÀÀµÀìÅÕ½Ðìͽ¹ÌѼáÕÑÅÕ½Ðì¤ Edited August 22, 2007 by weaponx
Delta01 Posted August 23, 2007 Author Posted August 23, 2007 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?
weaponx Posted August 23, 2007 Posted August 23, 2007 (edited) 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 August 23, 2007 by weaponx
Delta01 Posted August 24, 2007 Author Posted August 24, 2007 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
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