Sign in to follow this  
Followers 0
Rex

Close in interactive in XX min

1 post in this topic

I did this script long time ago.

I have now updatede it, to work even better (faster)

All it does is checking on mouse activitet, and if non for 2 hours then it shutsdown the computer.

; Generated by NewScript 4.5
;----------------------------------------------------------------------------
; Created:          26-07-2007 19:04:33
; Author:           //>Rex<\\
; Mail:             RexPrivat AT Hotmail DOT Com
; Version:          1.5
; AutoitVer:        3.2.4.9
; AutoItForum:
; Script Function:
; Shutwdown the Computer after 2 houers of interactivitet.
;
; By compairing on Mouse cordinats, and an internal counter
; the scripts calcultates how long time the computer (Mouse)
; hasn't been used, and if that period ar over 2 houers it starts
; a 60 sec.countdown with a progressbare, and when 10 sec again
; it beeps, until computer shutdown.
; Changelog:
;
; ----------------------------------------------------------------------------
#include <GUIConstants.au3> ; Includes GUIConstants.au3 to script
; Opt's Start > --------------------------------------------------------------
; Opt("RunErrorsFatal", 1)        ;1=fatal, 0=silent set @error
Opt("GUIOnEventMode", 1)        ;0=disabled, 1=OnEvent mode enabled
Opt("GUICloseOnESC", 0)         ;1=ESC  closes, 0=ESC won't close
; Opt("TrayIconDebug", 0)         ;0=no info, 1=debug line info
Opt("TrayMenuMode", 1)           ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID  not return
Opt("TrayOnEventMode", 1)        ;0=disable, 1=enable
; Opt("TrayIconHide", 0)          ;0=show, 1=hide tray icon
; Opt("TrayAutoPause",1)          ;0=no pause, 1=Pause
; Opt's End > ----------------------------------------------------------------
; Script start

;~ $Splash = SplashTextOn("","","25","0.1",@DesktopWidth - 90,1, "", "", 6, 100) ; Counter check

$exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "RealExit")
TraySetState()
TraySetIcon("shell32.dll", 20)
Global $Mouse1, $Mouse2
TraySetToolTip("Close if interactive...") ; Close if interactive English
;~ TraySetToolTip("Luk hvis interaktiv...") ; Close if interactive Danish
$n = 0 ; Counter

$ProgressTxt = " Shutingdown the computer" ; English
;~ $ProgressTxt = " Lukker computeren" ; Danish

$Label_1Txt = "When the progressbar hits 0, the computer shutsdown" ; English
;~ $Label_1Txt = "Når processbaren når 0 lukker computeren" ; Danish

$Label_2Txt = "Move the mouse to abort shutdown" ; English
;~ $Label_2Txt = "Bevæg musen for at afbryde lukning"; Danish

$Label_6Txt = "Sec. to shutdown" ; English
;~ $Label_6Txt = "Sek. til lukning" ; Danish

While 1
    _CheckMouse1() ; Goto get mouse pos first time
    Sleep(36000)
    $n = $n + 1 ; Adds 1 to the counter every min
    ;ControlSetText("", "", $Splash, $n,1 )
    _CheckMouse2() ; Goto func Get mouse pos second time
WEnd




Func _CheckMouse1()
    $pos1 = MouseGetPos()
    $Mouse1 = $pos1[0] + $pos1[1]

EndFunc   ;==>_CheckMouse1

Func _CheckMouse2()
    $pos2 = MouseGetPos()
    $Mouse2 = $pos2[0] + $pos2[1]

    If $Mouse1 <> $Mouse2 Then
        $n = 0
    ElseIf $Mouse1 = $Mouse2 And $n = 121 Then
        _ProgressOnClose()
    EndIf
EndFunc   ;==>_CheckMouse2

Func _ProgressOnClose()
    $Progress = GUICreate($ProgressTxt, 443, 111, -1, -1, $WS_OVERLAPPED + $WS_CAPTION, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

    $Label_1 = GUICtrlCreateLabel($Label_1Txt, 20, 8, 400, 20)
    GUICtrlSetFont(-1, 12, 900)
    $Label_2 = GUICtrlCreateLabel($Label_2Txt, 20, 30, 410, 20)
    GUICtrlSetFont(-1, 10, 600)
    $Label_4 = GUICtrlCreateLabel("60", 20, 80, 20, 20)
    $Progressbar1 = GUICtrlCreateProgress(20, 50, 405, 20)
    $Label_6 = GUICtrlCreateLabel($Label_6Txt, 40, 80, 90, 20)
    GUISetState()

    $Sec = 60 ; 1
    $secNew = $Sec ; 2
    $step = 100 / $Sec ; 3
    For $i = 100 To 0 Step (-$step) ; 1+2+3 Gives a 60 sec countdown
        $secNew = $secNew - 1
        GUICtrlSetData($Progressbar1, $i)
        GUICtrlSetData($Label_4, $secNew)
        Sleep(1000)

        $pos2 = MouseGetPos()
        $Mouse2 = $pos2[0] + $pos2[1]

        If $Mouse1 <> $Mouse2 Then
            GUIDelete($Progress)
            $n = 0
            ExitLoop
        EndIf

        If $secNew < 10 Then Beep(800, 200) ; Warning 10 sec before shutingdown
    Next

    If $secNew = 0 Then
        GUIDelete($Progress) ; Removes the progressbar before shutingdown
        Beep(800, 3000)
        Shutdown(9)
        Exit
    EndIf

EndFunc   ;==>_ProgressOnClose


Func RealExit()
    Exit
EndFunc   ;==>RealExit

/Rex

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