Sign in to follow this  
Followers 0
keotix

Inactive detection

3 posts in this topic

How would i get a script to: if inactive(no mouse and keyboard usage) for x amount of minutes, then continue to this part of the script

Share this post


Link to post
Share on other sites



search on forum with keyword "Idle time out"


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Certain Examples:

HotKeySet("{Esc}", "_Terminate")

Dim $last_active = 0
Dim $timer = TimerInit()

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then $timer = TimerInit()
    ToolTip(Int(TimerDiff($timer)/1000))
    Sleep(200)
WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)
    $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

#include <date.au3>; For _TicksToTime() only

Global $iIdleTime = _Timer_GetIdleTime()
ConsoleWrite("Debug: Idle time = " & $iIdleTime & "ms" & @LF)

Sleep(10 * 1000); 10sec

$iIdleTime = _Timer_GetIdleTime()
ConsoleWrite("Debug: Idle time = " & $iIdleTime & "ms" & @LF)

Global $Hr, $Min, $Sec
_TicksToTime($iIdleTime, $Hr, $Min, $Sec)
ConsoleWrite("Debug: Converted = " & $Hr & ":" & $Min & ":" & $Sec & @LF)

; ================================================
; function:  _Timer_GetIdleTime()
; purpose:  Returns the number of ticks since last user activity (i.e. KYBD/Mouse)
; syntax:  _Timer_GetIdleTime()
; returns:  On success:  integer ticks since last (approx. milliseconds) since last activity
; notes:  The current ticks since last system restart will roll over to 0 every 50 days or so,
;     which makes it possible for last user activity to be before the rollover, but run time
;     of this function to be after the rollover.  If this happens, @extended = 1 and the
;     returned value is ticks since rollover occured.
; author:  PsaltyDS at www.autoitscript.com/forum
; ================================================
; Change log:
; v1.0.0  --  03/20/2008 First version
; ================================================
Func _Timer_GetIdleTime()
  ; Get ticks at last activity
    Local $struct = DllStructCreate("uint;dword");
    DllStructSetData($struct, 1, DllStructGetSize($struct));
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
   
  ; Get current ticks since last restart
    Local $aTicks = DllCall("Kernel32.dll", "int", "GetTickCount")

  ; Return time since last activity, in ticks (approx milliseconds)
    Local $iDiff = $aTicks[0] - DllStructGetData($struct, 2)
    If $iDiff > 0 Then
      ; Normal return
        Return $iDiff
    Else
      ; Rollover of ticks counter has occured
        Return SetError(0, 1, $aTicks[0])
    EndIf
EndFunc ;==>_Timer_GetIdleTime

EDIT:

http://www.autoitscript.com/forum/index.ph...mp;#entry343430

http://www.autoitscript.com/forum/index.ph...l=idle+time+out

Edited by Bert

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  
Followers 0