#119844 - 2004-05-19 07:07 PM
Detect user idle or inactivity
|
@lejo @rias
Starting to like KiXtart
Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
|
Hi, whit kixtart How to Detect User Idle Time or Inactivity, and save in a variable that time...
pls
PD: I will run that script every 10 min with a sheduler task and If the user have a 10 mins in inactivity then run other task...
_________________________
Look always 4 the best...
|
|
Top
|
|
|
|
#119846 - 2004-05-19 07:14 PM
Re: Detect user idle or inactivity
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
you can also detect if the screensaver is active (look for the processname)
|
|
Top
|
|
|
|
#119847 - 2004-05-20 11:13 AM
Re: Detect user idle or inactivity
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
A very simple way to tell how idle your system is is to see how much time the system idle process is clocking up.
The script below checks how idle the system has been between each interval.
Code:
Break ON $=SetOption("Break","ON") $iIntervalCheck=30 ; Check every thirty seconds. $iThresholdValue=0,5,30,50,80,95 $sThresholdText="I have no time right now!", "Busy", "In use", "A little idle", "Idle", "Very Idle" $sThresholdColour="r+", "r", "y", "y+", "g", "g+" $strComputer = "." $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") If @ERROR @ERROR ": " @SERROR ? EndIf ; Get initial status $iLastTime=Int(@TICKS/1000) $iLastIdle=GetIdleSeconds() $iNumCPU=GetCPUCount() @TIME+" Waiting for first "+$iIntervalCheck+" second interval to expire, CPU count is "+$iNumCPU ? While Not KBHit() Sleep $iIntervalCheck $iThisIdle=GetIdleSeconds() $iThisTime=Int(@TICKS/1000) $iDeltaIdle=$iThisIdle-$iLastIdle $iDeltaTime=$iThisTime-$iLastTime $iPercentIdle=CInt(($iDeltaIdle*100/$iDeltaTime)/$iNumCPU) For $i=0 to 5 If $iPercentIdle>=$iThresholdValue[$i] $iIndex=$i EndIf Next
Color $sThresholdColour[$iIndex]/n Chr(13)+" "+CHR(13) @TIME+" Idle: "+$iPercentIdle+"% "+$sThresholdText[$iIndex]
$iLastIdle=$iThisIdle $iLastTime=$iThisTime Loop Get $ Exit 0 Function GetIdleSeconds() $GetIdleSeconds=0 $colItems = $objWMIService.ExecQuery('Select KernelModeTime from Win32_Process where Handle="0"',,48) For Each $objProcess in $colItems $GetIdleSeconds=$objProcess.KernelModeTime ; Time is in nanoseconds - Too much! $GetIdleSeconds=CInt(SubStr($GetIdleSeconds,1,Len($GetIdleSeconds)-7)) Exit 0 Next Exit 1 EndFunction Function GetCPUCount() $GetCPUCount=1 $colItems = $objWMIService.ExecQuery('Select NumberOfProcessors from Win32_ComputerSystem',,48) For Each $objComputer in $colItems $GetCPUCount=$objComputer.NumberOfProcessors Exit 0 Next Exit 1 EndFunction
|
|
Top
|
|
|
|
#119849 - 2004-05-20 11:36 AM
Re: Detect user idle or inactivity
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Question... does the running of this script affect the idleness ?
Yes of course to a small degree.
It is very low for reasonable intervals, and even when I had the interval as low as 3 seconds during testing the idle time was never below 100% when nothing else was running. For longer periods it will have less impact.
To test it, set the interval period to a 1 second, start task manager to monitor what it thinks CPU usage is and then start a process - I used "dir /s" in the root directory.
You will see that the values of idle time from the script and CPU time in task manager are pretty close.
If the script is going to be called by a scheduled task then the "last" values need to be stored in and recalled from the registry or a file, and a sanity check needs to be made to reset the values if the process is not run for some time, the machine is restarted or the counters wrap.
|
|
Top
|
|
|
|
#119850 - 2004-05-20 04:31 PM
Re: Detect user idle or inactivity
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
This might not be of any help to you right now... but i think shawn is going to expose This API in kixforms.... hopefuly soon See this thread on Kixforms BBS
Bryce
Edited by Bryce (2004-05-20 04:32 PM)
|
|
Top
|
|
|
|
#119853 - 2004-05-20 05:47 PM
Re: Detect user idle or inactivity
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
ahh Shawn just made a post on the kixforms board, this feature is a "work in progress"
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|