Jump to content

inactive computer...


eXorcist
 Share

Recommended Posts

Hello all,

Sorry for my english...

i need to write a script which detect the inactivity of Windows or of a specific program for x minutes.

If it's true, i launch a fonction (to log off from this program but not close it). if not, i wait...

i think a program like that :

Start

if inactive > 5 then

log off program Z

sleep 5 minutes

else

sleep 1 minute

go to Start

It will be more complicated but it's just to give you an idea of what i need.

I write a program using Task Sheduler from Windows XP but it's not good for using i need.

Thanks in advance for your help,

eXo

Link to comment
Share on other sites

Maybe this could help for the 5 minute of inactivity

Run("notepad.exe")

WinActivate("Untitled")
Sleep(2000);Give Notepad time to become active
While 1
    If NOT WinActive("Untitled") Then
        Sleep(300000)
        If NOT WinActive("Untitled") Then
            ;Whatever you want
            Exit;This is an example
        EndIf
    EndIf
WEnd
Exit

UNTESTED

Made this really quick, might not work ;)

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Thanks Kurt,

But the window could be active.. but not used (no mouse event and no keyboard event...)

So i think it's not solution

but thanks

Maybe this could help for the 5 minute of inactivity

Run("notepad.exe")

WinActivate("Untitled")
Sleep(2000);Give Notepad time to become active
While 1
    If NOT WinActive("Untitled") Then
        Sleep(300000)
        If NOT WinActive("Untitled") Then
            ;Whatever you want
            Exit;This is an example
        EndIf
    EndIf
WEnd
Exit

UNTESTED

Made this really quick, might not work ;)

Kurt

Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=4361

and here's my version that checks for a change in the size of a printscreen.

$TimeToCallTheFunction = 5000 ; in milliseconds

While 1
    $LastSize = _GetExtProperty(@ScriptDir & "\dump.jpg")
    DllCall("captdll.dll", "int", "CaptureScreen", "str", "dump.jpg", "int", 50)
    If _GetExtProperty(@ScriptDir & "\dump.jpg") <> $LastSize Then
        $Timer = TimerInit()
    ElseIf TimerDiff($Timer) > $TimeToCallTheFunction Then
        TheFunction()
    EndIf
    Sleep(1000)
WEnd


Func TheFunction()
    MsgBox(0,@ScriptName,"The system has been idle for " & Int($TimeToCallTheFunction/1000) & " seconds.")
EndFunc

Func _GetExtProperty($s_path,$i_prop = 1)
    $s_file = StringTrimLeft($s_path,StringInStr($s_path,"\",0,-1))
    $s_dir = StringTrimRight($s_path,(StringLen($s_path)-StringInStr($s_path,"\",0,-1)))
    $ShellApp = ObjCreate("shell.application")
    $oDir = $ShellApp.NameSpace($s_dir)
    $oFile = $oDir.Parsename($s_file)
    $property = $oDir.GetDetailsOf($oFile, $i_prop)
    If Not $property = "" Then 
        Return $property
    EndIf
EndFunc

You can get the DLL needed here

Edited by Manadar
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...