AutoHotkey Community

It is currently May 26th, 2012, 5:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 25th, 2009, 6:20 pm 
Offline

Joined: February 8th, 2009, 5:52 pm
Posts: 47
I'm spending way too much time on the computer.

Up to now, I was using a freeware app called TimeTracker to keep track of the total time I spend working on the computer per day. However it has a few nasty bugs and doesn't keep an accurate count under some circumstances. As it seems to be no longer developed, I tried looking for other free lightweight alternatives but couldn't find any, so I decided to quickly put something together using ahk.

Here you go. It's extremely simple (I'm new to the world of AHK) but i hope it can still be useful to some.

How to use it: there is nothing to configure, just launch it (best to have it
run at logon) and it will start tracking active usage time, based on mouse and keyboard input (the A_TIMEIDLE variable). Just hold down the right ctrl key to view the current usage for the day. The accuracy is +/-3 minutes.

For past data, you can check the track.txt file.


Code:

; TinyTracker 1.02 - A tiny computer usage tracker by lazygeek
;
; How to use it: there is nothing to configure, just launch it (best to have it
; run at logon) and it will start tracking active usage time, based on mouse
; and keyboard input (the A_TIMEIDLE variable). Just hold down the right
; ctrl key to view the current usage for the day. The accuracy is +/-3
; minutes.

menu, tray, icon, %A_WinDir%\system32\shell32.dll, 44
menu, tray, NoStandard
menu, tray, add, Exit, closeall
menu, tray, tip, TinyTracker 1.02

formatted :=0
SetTimer, aa, 60000 ; updates every 1 minute

aa:
formattime, thedate,,dd-MM-yyyy
IniRead, OutputVar, track.txt, %thedate%, mins, 0
 
if (A_TimeIdlePhysical<180000) {
 OutputVar++
 IniWrite, %OutputVar%, track.txt, %thedate%, mins
}
Return


FormatMinutes(NumberOfMinutes)  ; Convert mins to hh:mm
{
    time = 19990101 ; *Midnight* of an arbitrary date
    time += %NumberOfMinutes%,minutes
    FormatTime, mmss, %time%, H 'h' mm 'min'
    return mmss
}


rctrl::

formatted := FormatMinutes(OutputVar)
gui, add, text, w150 center, Usage today: %formatted%
gui, -sysmenu

gui, show,, TinyTracker 1.02
Keywait,rctrl, D
Keywait,rctrl
gui, destroy
return

closeall:
 exitapp



Edit: minor update to v1.02 with 2 fixes suggested by OceanMachine


Last edited by firace on March 5th, 2009, 5:17 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 12:14 am 
Offline

Joined: July 27th, 2008, 7:31 am
Posts: 47
Location: England
I'm still trying it out but I like this script, nice and easy and I think quite useful! Good one! :)

_________________
All scripts are untested unless otherwise mentioned.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 4:06 pm 
Offline

Joined: February 8th, 2009, 5:52 pm
Posts: 47
Robbo, glad you like it.

The script should be quite stable,
but if you encounter any bugs, please report.

Thanks for your feedback


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2009, 10:36 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Thanks, very useful.

I changed
Code:
menu, tray, icon, C:\WINDOWS\system32\shell32.dll, 44

to
Code:
menu, tray, icon, %A_WinDir%\system32\shell32.dll, 44

Because C:\ is not my system drive and so this should make it work whatever your system drive or name of windows folder (e.g. could be WINDOWS or WINNT or even user specified).

I also changed
Code:
if (A_TimeIdle<180000) {

to
Code:
if (A_TimeIdlePhysical<180000) {

So that any automated keystrokes or mouse clicks that my scripts may do while I am not there will not be counted as usage time.

But other than that it worked great, thanks very much for sharing it :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2009, 11:12 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
I just added the ability to track idle time as well as active time, and also to log the total time (although this is obvious as it's just a sum of the two other numbers).

Hope you dont mind.

Not sure if anyone would find this useful, but thought I would post it anyway:

Code:
#InstallKeybdHook
#InstallMouseHook
Menu, Tray, Icon, %A_WinDir%\system32\shell32.dll, 44
Menu, Tray, NoStandard
Menu, Tray, Add, Exit, closeall

SetTimer, CheckTime, 60000 ; updates every 1 minute

CheckTime:
   FormatTime, thedate,,dd-MM-yyyy
   IniRead, ActiveTime, track.txt, %thedate%, active, 0
   IniRead, IdleTime, track.txt, %thedate%, idle, 0

   If (A_TimeIdlePhysical < 60000) ; edited this line as per below
      ActiveTime++
   Else
      IdleTime++
   
   TotalTime := IdleTime + ActiveTime

   IniWrite, %ActiveTime%, track.txt, %thedate%, active
   IniWrite, %IdleTime%, track.txt, %thedate%, idle
   IniWrite, %TotalTime% , track.txt, %thedate%, total

Return

FormatMinutes(NumberOfMinutes)  ; Convert mins to hh:mm
{
   Time := 19990101 ; *Midnight* of an arbitrary date
   Time += %NumberOfMinutes%,minutes
   FormatTime, mmss, %time%, H 'h' mm 'min'
   Return mmss
}

rctrl::
   Gui, Add, Text, w150 Center, % "Active Time: " FormatMinutes(ActiveTime) "`nIdle Time: " FormatMinutes(IdleTime) "`nTotal: " FormatMinutes(TotalTime)
   Gui, -SysMenu
   
   Gui, Show
   Keywait,RCtrl, D
   Keywait,RCtrl
   Gui, Destroy
Return

closeall:
   ExitApp



Thanks again for writing and posting the original script, very useful :D

Edit: changed If (A_TimeIdle < 180000) to If (A_TimeIdlePhysical < 60000) as per below posts.
Edit: Added #InstallKeybdHook and #InstallMouseHook to ensure these are both being used, otherwise only the keyboard hook was being used, and hence mouse movement and clicks were being classed as "idle time" - see below quote:
help file for A_TimeIdlePhysical wrote:
If only one hook is installed, only its type of physical input affects A_TimeIdlePhysical (the other/non-installed hook's input, both physical and artificial, has no effect).


Last edited by OceanMachine on September 8th, 2010, 6:40 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 10:02 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Case 1: machine runs more than 24 hours in a session
Case 2: script is (accidentally) closed and rerun or machine rebooted multiple times

What will this script display in any of the above situations?

Suggestions:
1. include a "session" section to count total active/idle time during current session
2. include a "today" section to count active/idle time for the current day, regardless of interruptions
3. modify the script to run in Win9x too (icon number may need to be changed too for 9x):
Code:
A_SysDir := (A_OSType = "WIN32_NT") ? "32":""
A_SysDir := A_WinDir . "\System" . A_SysDir
Menu, Tray, Icon, %A_SysDir%\shell32.dll, 44
...
Could anyone post a screenshot of the XP icon so I could search for its 9x match?

The hotkey section needs to be modified too, since Win9x doesn't recognize RCTRL or any such L/R hotkey combination. Personally I set it to F6.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 2:16 am 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
The ini file is used to track the times, and is updated as soon as the 1 minute timer is fired. So yes, if the script is closed or rerun on a machine, it won't matter. the most you would be out by in any 1 counter would be 1 minute.

Regarding your points 1-3:

1: If the machine runs for more than 24 hours in one session, the times will still be posted as the date on which the script was run in that session, so if you opened the script on 3rd march and left it on for 30 hours, the total time would show for 30 hours on 3rd march (this is because the thedate variable is defined when the script is loaded). So, there shouldn't be a need for a session timer as this already works if you dont replace or close the script in the session (after midnight on the following day at least).

2: Assuming you want 1: to be obeyed as well, then this would need extra counters in there to count for the day and the session separately.

3: The only thing making it different on win9x is the icon and the hotkey, right? Well these can easily be changed, it doesn't have to be exactly the same on all OSs :) Maybe it would be possible to use the built in variables A_OSType and/or A_OSVersion to detect this and set things accordingly?

To stop the script being accidentally rerun while it is already running, you can add the following in the script (I usually put these at the top):
Code:
#SingleInstance ignore

The above directive will ignore the request to re-run the script, and just leave the old one running. Of course without this, the script will already ask you if you want to re-run the script and overwrite the currently running one anyway.

The icon is a little yellow star at the moment on XP, not sure if there is a similar one on Win9x?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 3:37 am 
Offline

Joined: February 8th, 2009, 5:52 pm
Posts: 47
Glad to see this is generating some interest and nice suggestions 8).

I have amended the code in the original post with the 2 fixes suggested by OceanMachine. Thanks for this.

However, I will probably not be able to further update this script in the near future.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 4:57 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Hey OceanMachine, thanks for the details. Also thanks lazygeek for the initial script (should've said that in first post :oops: ).
Icon and hotkey apart, what I had in mind was basically a day counter for the current session. Something like:

Current session: 3 days 14 hours 25 minutes
Today's active: 4 hours 52 minutes
Today's idle: 0 hours 22 minutes

What I find odd is that the script has recorded 0 idle minutes, both yesterday and today (using OceanMachine's script version). I even lowered the idle check interval to 10,000 (10 sec) to no avail; there may be something wrong with that function under Win9x. :?

There's no yellow star in 98SE, not in shell32.dll at least. I'd settle for icon 25 instead, which is a file with an hourglass at the bottom-left. Or we could use one of the icons at famfamfam.com.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 2:00 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Bear in mind that if you alter the timer value (from 60000) then you will also need to change the time interval check in the sub that is called by the timer. Additionally, changing this will mean that (for example) every 10 seconds your 'minute' counter would increase by one, so you would need to add some maths in there to only increment the minutes count if you were idle 6 times (if you had 10 seconds for the check frequency).

This made me notice that in my post with the idle timer modifications, I firstly didnt have A_TimeIdlePhysical in there (as per my original post in this thread - oops!), and secondly that the check is for 180000ms, not 60000ms as it should be for 1 minute.

@LazyGeek: you probably want to change
Code:
 If (A_TimeIdlePhysical<180000)
to
Code:
 If (A_TimeIdlePhysical<60000)
in your script otherwise you will only be recorded as not being active if you are idle for 3 minutes or more! :) ...unless there is something I am missing of course!

I have modified the script in my second post accordingly.

@Drugwash: With regard to the idle time not working:
Quote:
From The AHK help File:
A_TimeIdle: ...This variable will be blank unless the operating system is Windows 2000, XP, or beyond...

Sorry Drugwash, looks like there is no idle time for you using that built in variable under Win9x.

In fact, all this script will do under Windows 9x is record how many minutes the script has been open for on any given day (as every time the Timer sub is fired, A_IdleTime will be blank, hence it will always increment ActiveTime), not how long the computer has been in use for.

Sorry Drugwash, looks like this will not do what you need under Win9x, you may have to find a way to do this by detecting key presses or mouse movements and resetting a timer when you detect them or something like that?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 2:19 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Yeah, figures. Also, it's funny that in a tool called AutoHotkey, hotkeys are the least usable (for 9x users), to begin with. Oh well... :(

Come to think about it, if the screensaver can detect activity, why the heck can't AHK do it too? Hmmm... food for thought (when my brains will stop boiling in own juice, that is).

See ya!

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 2:35 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Quote:
Come to think about it, if the screensaver can detect activity, why the heck can't AHK do it too?


It can, its just that you have to do it another way, AHK doesn't provide a built-in variable that gives you that number to Win98 Users (assuming this is a limitation of the OS).

However you can 'manually' implement the same thing given a bit of work :)


Last edited by OceanMachine on March 5th, 2009, 8:51 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 2:48 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
I know but that'd be Chris' job not mine... :twisted:

I'll take a look at Miranda's idle detection routine... probably... someday. :roll:

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2009, 8:47 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
That's just plain lazy...

It's not Chris's job at all, he has provided the platform upon which you can do what you like... if you should chose to use it to detect idle time, you can. He has been kind enough to provide a built in way to find the idle time on semi-recent operating systems... however not for those that went out with the ark, probably due to differences in the OS. Therefore you will have to do it in the same way that might approach any other problem and wish to solve it with AHK, and for which there isn't a nice easy built in variable... code it yourself :)

The vast majority of times we develop code there isn't a built in variable that gives you exactly what you need (in any platform), so the usual way is to generate that data yourself, not to start saying it is the developers job to provide you with a built in variable!

Good luck anyway :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2009, 12:27 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
My point of view is that as long as there is a built-in function, it should work on all Win versions. At least that would be the kindest way to do things.

I can understand when due to many missing functions or libraries, there can't be overall compatibility (say, multi-monitor support for Win95/NT).

I've been working on a few scripts - mostly for personal usage - and although I'm running 98SE and couldn't care less about Win2000+, I've done my best (nagging neighbors and friends) to test and fix any issues that may appear while running under those OS versions. A little help in return would be welcome, IMHO.

Now, let's drop this silly argue and try to be constructive. I've promised I'd look into those Miranda sources and will do it, just as soon as I feel better after this bad cold. And I apologyze if any of my statements above looks rude - it's most likely the effect of the illness and medicine; don't wanna offend anyone. :oops:

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group