Jump to content

Computer idle time


scriptme
 Share

Go to solution Solved by scriptme,

Recommended Posts

Hi all. This is my first time posting. I have trying to figure out how to create a script that will determine if a user has been idle. I have a script that I found on autoscript.com but would like this script to output the results in real time in hours/minutes/seconds. This script only outputs the idle time after a key has been pressed:

Any help would be appreciated:

; User/System Idle Time
 
#include <Date.au3>
HotKeySet("{Esc}", "_Terminate")
 
Local $last_active = 0, $iHours, $iMins, $iSecs
Local $not_idle = _CheckIdle($last_active, 1)
while (1)
    Sleep(200)
    $not_idle = _CheckIdle($last_active)
    _TicksToTime($not_idle, $iHours, $iMins, $iSecs)
 
    If $iHours or $iMins Or $iSecs Then
        ConsoleWrite("Was Idle for: Hours: " & $iHours & " Minutes: " & $iMins & " Seconds: " & $iSecs & @LF)
    EndIf
WEnd
 
Func _CheckIdle(ByRef $last_active, $start = 0)
    Local $struct = DllStructCreate("uint;dword");
    DllStructSetData($struct, 1, DllStructGetSize($struct));
    If $start Then
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        $last_active = DllStructGetData($struct, 2)
        Return $last_active
    Else
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        If $last_active <> DllStructGetData($struct, 2) Then
            Local $save = $last_active
            $last_active = DllStructGetData($struct, 2)
            Return $last_active - $save
        EndIf
    EndIf
EndFunc ;==>_CheckIdle()
 
Func _Terminate()
    Exit
EndFunc ;==>_Terminate
Link to comment
Share on other sites

_Timer_GetIdleTime, the function is in the Timers.au3 in case you want to see how that one is constructed, or if you would like to use that instead.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I would like to use _TicksToTime in Date.au3 so I can get idle time in Hours/Minutes/Seconds unless that's possible with _Timer_GetIdleTime. I just can't seem to figure out how to get a realtime output from the above script. Is there a way to do that? 

Link to comment
Share on other sites

looks like this _Timer_GetIdleTime() only returns milliseconds so it would take a lil bit of conversions to get that to translate out to hours,min,sec ect.  

to get the real time output your gona have to put it into a loop that runs......well constantly

edit . THis ain't pretty but it gives a realtime output 

HotKeySet("{ESC}","exit1")
while 1
$time = _Timer_GetIdleTime()
$sec = Floor($time/1000)
$min = Floor($sec/60)

$hour = Floor($min/60)

MsgBox("","idletime",$hour & ":" & $min & ":" & $sec & "." & $time,.5)


WEnd
Func exit1()
   Exit
   EndFunc
Edited by markyrocks
Link to comment
Share on other sites

_Timer_GetIdleTime returns ticks, not milliseconds, using that in conjunction with _TicksToTime would convert the ticks into hours/mins/secs, which should give you the information you need. Unless of course the idle time exceeds approximately 50 days, because then the idle timer rolls over.

As to real time output, I'm not sure what you mean by that. Do you want a display in the console as it's idle or after it's not idle?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here's a demo of how to display the idle time in the console as it's running.

#include <Timers.au3>
#include <Date.au3>

HotKeySet("{ESC}", "_Exit")
Global $iIdleTime, $iHours, $iMinutes, $iSeconds
While 1
    $iIdleTime = _Timer_GetIdleTime()
    _TicksToTime($iIdleTime, $iHours, $iMinutes, $iSeconds)
    ConsoleWrite("Idle time = " & StringFormat("%02s", $iHours) & ":" & StringFormat("%02s", $iMinutes) & ":" & StringFormat("%02s", $iSeconds) & @CRLF)
    Sleep(1000)
WEnd
Func _Exit()
    Exit
EndFunc   ;==>_Exit

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Symantics....

Return ValueSuccess:integer ticks since last (approx. milliseconds) since last activityFailure:Sets @extended = 1 if rollover occurs (see remarks)

It says approximately milliseconds because of the accuracy of the timer, so you can assume it's giving you milliseconds, but for accurate timing you shouldn't make that assumption. In the case of the needs of this script, the accuracy isn't that important.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...