Sign in to follow this  
Followers 0
SpookMeister

How to check if system is idle

38 posts in this topic

I did a few searchs, thinking this must have come up before.. but none of the results seamed to be what I was looking for.

I want to do something based on how long its been since the mouse has moved (I know how to do that) or any keys have been pressed (not sure on that part).

Or better yet, maybe there is some dll call I can make to tell me this info instead of polling for it directly in a script. Ideas anyone?


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites



I did a few searchs, thinking this must have come up before.. but none of the results seamed to be what I was looking for.

I want to do something based on how long its been since the mouse has moved (I know how to do that) or any keys have been pressed (not sure on that part).

Or better yet, maybe there is some dll call I can make to tell me this info instead of polling for it directly in a script. Ideas anyone?

you're right in that this has come up before... about 6 months ago i posted a solution to the same question... let me look back through my posts and i'll link you

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

you're right in that this has come up before... about 6 months ago i posted a solution to the same question... let me look back through my posts and i'll link you

found one...

Opt("TrayIconDebug",1)
dim $oldpos[2]
dim $pos[2]
#include <Misc.au3>
HotKeySet("{Esc}","_Exit")
Dim $s_keys[117] = [116, _
"01","02","04","05","06","08","09","0C","0D","10", _
"11","12","13","14","1B","20","21","22","23","24", _
"25","26","27","28","29","2A","2B","2C","2D","2E", _
"30","31","32","33","34","35","36","37","38","39", _
"41","42","44","45","46","47","48","49","4A","4B","4C", _
"4D","4E","4F","50","51","52","53","54","55","56","57","58","59", _
"5A","5B","5C","60","61","62","63","64","65","66", _
"67","68","69","6A","6B","6C","6D","6E","6F","70", _
"71","72","73","74","75","76","77","78","79","7A", _
"7B","7C","7D","7E","7F","80H","81H","82H","83H","84H", _
"85H","86H","87H","90","91","A0","A1","A2","A3","A4","A5"]
$dll = DllOpen("user32.dll")

$pos = MouseGetPos()

$start = TimerInit()
While 1
Sleep ( 100 )
For $y = 1 To $s_keys[0]
If _IsPressed($s_keys[$y], $dll) Then 
$start = TimerInit()
EndIf
Next
$oldpos[0] = $pos[0]
$oldpos[1] = $pos[1]
$pos = MouseGetPos()
if Not $oldpos[1] = $pos[1] Or not $oldpos[0] = $pos[0] Then
$start = TimerInit()


EndIf
if TimerDiff($start) > 10000 Then
MsgBox(0,"inactive","you have not pressed any keys or used your mouse for 10 seconds")
$start = TimerInit()
Else

EndIf
WEnd
Func _Exit()
DllClose($dll)
Exit
EndFunc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thanks Cam


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Thanks Cam

glad i could help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

found one...

Opt("TrayIconDebug",1)
dim $oldpos[2]
dim $pos[2]
#include <Misc.au3>
HotKeySet("{Esc}","_Exit")
Dim $s_keys[117] = [116, _
"01","02","04","05","06","08","09","0C","0D","10", _
"11","12","13","14","1B","20","21","22","23","24", _
"25","26","27","28","29","2A","2B","2C","2D","2E", _
"30","31","32","33","34","35","36","37","38","39", _
"41","42","44","45","46","47","48","49","4A","4B","4C", _
"4D","4E","4F","50","51","52","53","54","55","56","57","58","59", _
"5A","5B","5C","60","61","62","63","64","65","66", _
"67","68","69","6A","6B","6C","6D","6E","6F","70", _
"71","72","73","74","75","76","77","78","79","7A", _
"7B","7C","7D","7E","7F","80H","81H","82H","83H","84H", _
"85H","86H","87H","90","91","A0","A1","A2","A3","A4","A5"]
$dll = DllOpen("user32.dll")

$pos = MouseGetPos()

$start = TimerInit()
While 1
Sleep ( 100 )
For $y = 1 To $s_keys[0]
If _IsPressed($s_keys[$y], $dll) Then 
$start = TimerInit()
EndIf
Next
$oldpos[0] = $pos[0]
$oldpos[1] = $pos[1]
$pos = MouseGetPos()
if Not $oldpos[1] = $pos[1] Or not $oldpos[0] = $pos[0] Then
$start = TimerInit()


EndIf
if TimerDiff($start) > 10000 Then
MsgBox(0,"inactive","you have not pressed any keys or used your mouse for 10 seconds")
$start = TimerInit()
Else

EndIf
WEnd
Func _Exit()
DllClose($dll)
Exit
EndFunc

This thread is so ancient am wondering if this is still valid.

Share this post


Link to post
Share on other sites

This thread is so ancient am wondering if this is still valid.

I wrote one very similar to this recently (using 3.3.0.0) if you are looking for some help with it.

-Aaron

Share this post


Link to post
Share on other sites

Yea, sure, where is it?

I didn't find anything browsing your previous posts.

Share this post


Link to post
Share on other sites

Yea, sure, where is it?

I didn't find anything browsing your previous posts.

;******************************************************************************
;------------------------------ PRE-SCRIPT ------------------------------------
;******************************************************************************
;%%%%%%% OPTIONS %%%%%%%
Opt("CaretCoordMode", 1)        ;1=absolute, 0=relative, 2=client
Opt("ExpandEnvStrings", 0)      ;0=don't expand, 1=do expand
Opt("ExpandVarStrings", 0)      ;0=don't expand, 1=do expand
Opt("FtpBinaryMode", 1)         ;1=binary, 0=ASCII
Opt("GUICloseOnESC", 1)         ;1=ESC  closes, 0=ESC won't close
Opt("GUICoordMode", 1)          ;1=absolute, 0=relative, 2=cell
Opt("GUIDataSeparatorChar","|") ;"|" is the default
Opt("GUIOnEventMode", 0)        ;0=disabled, 1=OnEvent mode enabled
Opt("GUIResizeMode", 0)         ;0=no resizing, <1024 special resizing
Opt("GUIEventOptions",0)        ;0=default, 1=just notification, 2=GuiCtrlRead tab index
Opt("MouseClickDelay", 10)      ;10 milliseconds
Opt("MouseClickDownDelay", 10)  ;10 milliseconds
Opt("MouseClickDragDelay", 250) ;250 milliseconds
Opt("MouseCoordMode", 1)        ;1=absolute, 0=relative, 2=client
Opt("MustDeclareVars", 0)       ;0=no, 1=require pre-declare
Opt("PixelCoordMode", 1)        ;1=absolute, 0=relative, 2=client
Opt("SendAttachMode", 0)        ;0=don't attach, 1=do attach
Opt("SendCapslockMode", 1)      ;1=store and restore, 0=don't
Opt("SendKeyDelay", 5)          ;5 milliseconds
Opt("SendKeyDownDelay", 1)      ;1 millisecond
Opt("TCPTimeout",100)           ;100 milliseconds
Opt("TrayAutoPause",1)          ;0=no pause, 1=Pause
Opt("TrayIconDebug", 0)         ;0=no info, 1=debug line info
Opt("TrayIconHide", 0)          ;0=show, 1=hide tray icon
Opt("TrayMenuMode",0)           ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID  not return
Opt("TrayOnEventMode",0)        ;0=disable, 1=enable
Opt("WinDetectHiddenText", 0)   ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 1)     ;0=no, 1=search children also
Opt("WinTextMatchMode", 1)      ;1=complete, 2=quick
Opt("WinTitleMatchMode", 1)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinWaitDelay", 250)        ;250 milliseconds
;****** THIS WAS REMOVED IN v3.3.4 *******
Opt("OnExitFunc","OnExit");"OnAutoItExit" called
;*****************************************
;%%%%%% INCLUDES %%%%%%%
#include <Misc.au3>


;%%%%%% CONSTANTS %%%%%%
Global Const $gc_prog_name = "Keep Awake"
Global Const $gc_version = "v1.1"
Global Const $gc_szVersion = $gc_prog_name & " - " & $gc_version
Global Const $num_keys = 120
Global Const $seconds_keep_alive = 290
Global Const $ms_check_delay = 100 ;In milliseconds (<=1000)
Global Const $dll = DllOpen("user32.dll")
Global Const $avArray[$num_keys] = [ _ ; Hex codes for keys
"01", _
"02", _
"04", _
"05", _
"06", _
"08", _
"09", _
"0C", _
"0D", _
"10", _
"11", _
"12", _
"13", _
"14", _
"1B", _
"20", _
"21", _
"22", _
"23", _
"24", _
"25", _
"26", _
"27", _
"28", _
"29", _
"2A", _
"2B", _
"2C", _
"2D", _
"2E", _
"30", _
"31", _
"32", _
"33", _
"34", _
"35", _
"36", _
"37", _
"38", _
"39", _
"41", _
"42", _
"43", _
"44", _
"45", _
"46", _
"47", _
"48", _
"49", _
"4A", _
"4B", _
"4C", _
"4D", _
"4E", _
"4F", _
"50", _
"51", _
"52", _
"53", _
"54", _ 
"55", _
"56", _
"57", _
"58", _
"59", _
"5A", _
"5B", _
"5C", _
"60", _
"61", _
"62", _
"63", _
"64", _
"65", _
"66", _
"67", _
"68", _
"69", _
"6A", _
"6B", _
"6C", _
"6D", _
"6E", _
"6F", _
"70", _
"71", _
"72", _
"73", _
"74", _
"75", _
"76", _
"77", _
"78", _
"79", _
"7A", _
"7B", _
"7C", _
"7D", _
"7E", _
"7F", _
"80H", _
"81H", _
"82H", _
"83H", _
"84H", _
"85H", _
"86H", _
"87H", _
"90", _
"91", _
"BA", _
"BB", _
"BC", _
"BD", _
"BE", _
"BF", _
"C0", _
"DB", _
"DC", _
"DD"]

;%%%%%% GLOBAL VARS %%%%%%%
Global $ms_x, $ms_y, $i = 0, $r = 1

;%%%%%% INIT %%%%%%
; Keep only one instance of this program running
If WinExists($gc_szVersion) Then Exit ; It's already running
AutoItWinSetTitle($gc_szVersion)

; Determine number of loops before keep-alive
$r = Floor((1000 / $ms_check_delay) * $seconds_keep_alive)

; Set Exit Fuction
;****** THIS WAS ADDED IN v3.3.2 *********
;OnAutoItExitRegister("OnExit")
;*****************************************

;******************************************************************************
;--------------------------------- SCRIPT -------------------------------------
;******************************************************************************
While 1
    While $i < $r
        $ms_x = MouseGetPos(0)
        $ms_y = MouseGetPos(1)
        Sleep($ms_check_delay)
        ; Check for mouse movement
        If ($ms_x <> MouseGetPos(0)) OR ($ms_y <> MouseGetPos(1)) Then
            $i = 0
        EndIf
        ; Check for keystrokes or mouse clicks
        For $k = 0 to UBound($avArray) - 1
            If _IsPressed($avArray[$k], $dll) Then
                $i = 0
            EndIf
        Next
        $i += 1
    WEnd
    MouseMove(Random(0,@Desktopwidth),Random(0,@DesktopHeight),15)
    $i = 0
WEnd
;End of program
Exit

;%%%%%% FUNCTIONS %%%%%%%
Func OnExit()
    DllClose($dll)
EndFunc


;******************************************************************************
;------------------------------- END SCRIPT -----------------------------------
;******************************************************************************

If you want to make it so it just let's you know, just replace the mouse move.

Share this post


Link to post
Share on other sites

You just want to detect idle time? Try this:

#include <Timers.au3>

Global $iLimit = 10 ; Idle limit in seconds

HotKeySet("{ESC}", "_Quit")

AdlibRegister("_CheckIdleTime", 500)

While 1
    Sleep(20)
WEnd

Func _CheckIdleTime()
    If _Timer_GetIdleTime() > $iLimit * 1000 Then MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds...  Get busy!", 3)
EndFunc   ;==>_CheckIdleTime

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Much simpler.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I'm having something similar to detecting desktop idle: based on a text file which holds the duration of idle time required to kick in the process (line determine from file in $sav, 4). However, its not working as expected so any help would be appreciated.

Func _IdleTicks()
;~  ;Dim $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // only for example then you will read this value in the config file
    Local $h_GTC = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $i_Ticks_Init = $h_GTC[0]
    Local $struct = DllStructCreate('uint;dword')
    Local $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // read from value in the config file
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $i_TicksSinceIdle = DllStructGetData($struct, 2)

    If ($i_Ticks_Init - $i_TicksSinceIdle) > $i_WaitIdleTime Then
        MsgBox(64, "", "Now we can start the screensaver")
    EndIf
EndFunc  ;==>_IdleTicks

I can post the full code if needed. I cannot wrap my head around this one but basically its to kick the screensaver ON after the time stored in $sav, 4 (which is a line in a file that stores max idle timeout in minutes) is reached.

Share this post


Link to post
Share on other sites

You just want to detect idle time? Try this:

#include <Timers.au3>

Global $iLimit = 10 ; Idle limit in seconds

HotKeySet("{ESC}", "_Quit")

AdlibRegister("_CheckIdleTime", 500)

While 1
    Sleep(20)
WEnd

Func _CheckIdleTime()
    If _Timer_GetIdleTime() > $iLimit * 1000 Then MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds...  Get busy!", 3)
EndFunc   ;==>_CheckIdleTime

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Much simpler.

;)

Wow...I definitely over complicated things :)

Share this post


Link to post
Share on other sites

It should work, assuming FileReadLine($sav, 4) returns a valid result.

Global $sav = @ScriptDir & "\Test1.txt"
FileWriteLine($sav, "null" & @CRLF & "null" & @CRLF & "null" & @CRLF & "10000" & @CRLF & "null")
Sleep(11000)
_IdleTicks()

Func _IdleTicks()
;~  ;Dim $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // only for example then you will read this value in the config file
    Local $h_GTC = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $i_Ticks_Init = $h_GTC[0]
    Local $struct = DllStructCreate('uint;dword')
    Local $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // read from value in the config file
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $i_TicksSinceIdle = DllStructGetData($struct, 2)

    If ($i_Ticks_Init - $i_TicksSinceIdle) > $i_WaitIdleTime Then
        MsgBox(64, "", "Now we can start the screensaver")
    EndIf
EndFunc   ;==>_IdleTicks

How is it not working as expected?

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks Salty..

What happens is two things:

1) The screensaver still does not wait to show the image transitions -- they just happen immediately, and

2) When the user moves the mouse, instead of going to the password box it just fades to black and nothing happens.

As a backup I use this code:

; _IdleTicks
Func _IdleTicks()
    Local $aTSB = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $ticksSinceBoot = $aTSB[0]
    Local $struct = DllStructCreate('uint;dword')
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $ticksSinceIdle = DllStructGetData($struct, 2)
    If ($ticksSinceBoot - $ticksSinceIdle) < $lticks Then Return 1
    $lticks = ($ticksSinceBoot - $ticksSinceIdle)
    ;Return ($ticksSinceBoot - $ticksSinceIdle)
EndFunc   ;==>_IdleTicks
As that brings up the password box when the mouse/keyboard are touched but that code above is not connected to my "$sav, 4" location where it supposed to read that 4th line to get the idle time out info. That is where I am stuck.

Share this post


Link to post
Share on other sites

Any thoughts on this?

Share this post


Link to post
Share on other sites

Since I don't have your file to read, all I changed was:

Local $i_WaitIdleTime = 10000
After that, it works fine for me. Are you comparing an integer value to a string read from the file? Maybe you need:
Local $i_WaitIdleTime = Int(FileReadLine($sav, 4))

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

hehe. yeah I tried:

Local $i_WaitIdleTime = 10000

No dice..

What happens is the same:

1) The screensaver still does not wait to show the image transitions -- they just happen immediately (once the autoit script runs), and

2) Once the screensaver shows the images, if the user moves the mouse, instead of going to the password box it just fades to black and nothing happens freezing the screen it place with a blank black screen. I have to ctrl-alt-delete out. ;)

Share this post


Link to post
Share on other sites

Image transitions? Password box? There's none of that stuff in the little code snippet we were discussing. Aren't those problems outside the _IdleTicks() function? What code are you running?

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Sorry Salty.. here is the full code I posted it in this thread! Its changed slightly here and there but generally its remained the same.

Share this post


Link to post
Share on other sites

Hey Salty/anyone.. were you able to see whats going wrong? I seriously could use another autoit scripter's opinion there.

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