Jump to content
Sign in to follow this  

Set time every 5 min

Recommended Posts


I'm working on a script that shows how many hours/minutes/secs I'm working on the computer.

This works perfect, but now I want save every 5 min to a text file to get the total hours.

The problem is that the first 5min work, but then I can't get it work.

The timer must save it to 10min but he doesn't do that.

Here is the script:

#include <GUIConstants.au3>
#include <Date.au3>

Global $Secs, $Mins, $Hour, $Time

;Create GUI
GUICreate("Timer",200, 200)
GUICtrlCreateLabel("00:00:00", 10,10)

;Start timer
$timer = TimerInit()
AdlibEnable("Timer", 50)
$StartTicks = _TimeToTicks("00:00:00")

While 1
  $msg = GUIGetMsg()

;If time is 1 sec -> next time 5 min
    if ($Time = "00:00:01") Then
 ;Set time to 5 min
  $EndTicks = $StartTicks + 5 * 60 * 1000
$next = "0" & $Hour & ":0" & $Mins & ":0" & $Secs

;If time is 5min -> show message
msgbox(0,"Next time",$next)

;Filewrite now 5 minutes to a txt file
;If time is 10min -> save time


 ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
Case $msg = $GUI_EVENT_CLOSE
    ;Show the total time of the program
      msgbox(64,"Total time of this session:",$Time)

;Function timer
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

I removed the part that must to +5min because that always sucks.

Can anyone please help me?



Share this post

Link to post
Share on other sites


Take a look at TimerInit, TimerDiff and Adlibenable. Make shure you understand how the samples work and do some search on the forum. Do the search in the header only is often more productive than the default option.

This code should write to a log every 5min(not tested:)):

Adlibenable("writelog", 5*60*1000) ;use milliseconds
While GetGuMsg() <> -3
Func WriteLog()
    ConsoleWrite("WriteLog called: " & @Min & ":" & @SEC & @LF)

The sample you have used as a starting point is not the best for your application. Also, do you want to log how long your script has been runnning or how long you have been working (as in done some activity. keyboard input mouse movements)?

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...