Rex Posted September 26, 2005 Share Posted September 26, 2005 I'd this script for my parents, becourse my father often forgot to shutdown the computer. The script works (as far that i know), how ever i wonder if there shoulden be another and maby easyer way to check for interactivitet for XX time. Any of U fokes have an expandcollapse popup#include <GUIConstants.au3>; Includes GUIConstants.au3 to script) ;This script will close the computer if it has ben inaktive for 3 hours. ; The way it checks for inaktivitet is to check on the mouse curser, if the mouse curser has't ;moved for 3 hour it will throw a msg. that says that the computer will be shutdown in 100 sec. ; We count the 60 sec down in a progressbar, however if the user clicks Cancle or moves the mouse ; The shutdown ic suspended for the next 2 hours. Opt("GUICloseOnESC", 0) ;1=ESC won't close, 0=ESC closes Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled Opt("RunErrorsFatal", 0) ;1=fatal, 0=silent set @error Opt("TrayMenuMode", 1) Opt("TrayOnEventMode",1) ;Opt("TrayIconDebug", 1) $exit = TrayCreateItem("Exit") TrayItemsetOnEvent(-1, "RealExit") TraySetState() TraySetIcon("shell32.dll", 20) Global $Mouse1, $Mouse2 TraySetToolTip("Luk hvis interaktiv..."); Close if interactive While 1 _CheckMouse1() Sleep(5000) ;Sleep(7200000); Sleep for 2 hours Sleep(3600000); Sleep for 1 hour _CheckMouse2() WEnd Func _CheckMouse1() $pos1 = MouseGetPos() $Mouse1 = $pos1[0]+$pos1[1] EndFunc Func _CheckMouse2() $pos2 = MouseGetPos() $Mouse2 = $pos2[0]+$pos2[1] If $mouse1 = $Mouse2 Then _ProgressOnClose() EndIf EndFunc Func _ProgressOnClose() $Progress = GuiCreate(" Lukker computeren ", 443, 111, -1, -1, $WS_OVERLAPPED+$WS_CAPTION, $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST) $Label_1 = GuiCtrlCreateLabel("Når processbaren når 0 lukker computeren", 20, 8, 400, 20) GUICtrlSetFont (-1, 12, 900) $Label_2 = GuiCtrlCreateLabel("Bevæg musen for at afbryde lukning", 20, 30, 410, 20) GUICtrlSetFont (-1, 10, 600) $Label_4 = GuiCtrlCreateLabel("100", 20, 80, 20, 20) $Progressbar1 = GuiCtrlCreateProgress(20, 50, 405, 20) $Label_6 = GuiCtrlCreateLabel("Sek. til lukning", 40, 80, 90, 20) GUISetState () $s = 100 $ss = 0 For $i = $s To $ss Step -1 GUICtrlSetData ($progressbar1, $i) GUICtrlSetData($label_4, $i) $pos2 = MouseGetPos() $Mouse2 = $pos2[0]+$pos2[1] Beep(800, 200) If $Mouse1 <> $Mouse2 Then GUIDelete($Progress) ExitLoop EndIf Sleep(800) Next If $i = -1 Then GUIDelete($Progress) Beep(800, 3000) Shutdown(9) Exit EndIf EndFunc Func RealExit() Exit EndFunc /Rex Link to comment Share on other sites More sharing options...
jefhal Posted September 26, 2005 Share Posted September 26, 2005 Here's an idea that might be a worthwhile addition to your great script!: Check to see what programs are running at shutdown time, and see if there are any unsaved documents. If there are unsaved documents, do a save, but give the documents a new name like "unsaved_1.doc" just in case the original "unsaved.doc" had been changed but your parents did not want to save the changes. You would have to determine what their primary programs are first, of course... ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
poisonkiller Posted September 27, 2005 Share Posted September 27, 2005 I tried to make program like yours. #NoTrayIcon HotKeySet("^c", "Terminate") $pos1 = MouseGetPos() $mpos1 = $pos1[0]+$pos1[1] While 1 Sleep(720000) $pos2 = MouseGetPos() $mpos2 = $pos2[0]+$pos2[1] If $mpos1 <> $mpos2 Then Run(@ScriptName) Exit 0 Else ProgressOn("Shutdown", "Press Ctrl+C to cancel", "%") For $prog = 0 to 100 step 1 Sleep(1000) ProgressSet($prog, $prog &"%") Next ProgressOff() Shutdown(1) Exit 0 EndIf Wend Func Terminate() Sleep(1000) Exit 0 EndFunc I think this is easier way to shutdown. But i have to say your prog is better. You have to compile my script, because "Run()" is working only .exe And sorry about my bad english language! Link to comment Share on other sites More sharing options...
Rex Posted September 27, 2005 Author Share Posted September 27, 2005 I tried to make program like yours. #NoTrayIcon HotKeySet("^c", "Terminate") $pos1 = MouseGetPos() $mpos1 = $pos1[0]+$pos1[1] While 1 Sleep(720000) $pos2 = MouseGetPos() $mpos2 = $pos2[0]+$pos2[1] If $mpos1 <> $mpos2 Then Run(@ScriptName) Exit 0 Else ProgressOn("Shutdown", "Press Ctrl+C to cancel", "%") For $prog = 0 to 100 step 1 Sleep(1000) ProgressSet($prog, $prog &"%") Next ProgressOff() Shutdown(1) Exit 0 EndIf Wend Func Terminate() Sleep(1000) Exit 0 EndFuncI think this is easier way to shutdown. But i have to say your prog is better. You have to compile my script, because "Run()" is working only .exeAnd sorry about my bad english language! Yous script do almost the same as mine but where my script just keep sleeping if there is movment, your's "re run" the exe file and exit's, also my script "kills" the shutdown if the user moves the mouse where in your's the user have to hit the hotkey, and that shutdowns the entire script ( my script is like a duracell, it just keep on going until the user exit's it in the systray or shutsdown the puter).But depending on what U need, both scripts are useable Link to comment Share on other sites More sharing options...
Rex Posted September 27, 2005 Author Share Posted September 27, 2005 Here's an idea that might be a worthwhile addition to your great script!: Check to see what programs are running at shutdown time, and see if there are any unsaved documents. If there are unsaved documents, do a save, but give the documents a new name like "unsaved_1.doc" just in case the original "unsaved.doc" had been changed but your parents did not want to save the changes. You would have to determine what their primary programs are first, of course...Hmm that i don't know how to do... Link to comment Share on other sites More sharing options...
Cape-City Posted October 3, 2005 Share Posted October 3, 2005 (edited) I tried to make program like yours. ProgressOn("Shutdown", "Press Ctrl+C to cancel", "%") For $prog = 0 to 100 step 1 Sleep(1000) ProgressSet($prog, $prog &"%") Next ProgressOff()Maybe better use this part :ProgressOn("Shutdown", "Press Ctrl+C to cancel", "0%") For $prog = 1 to 100 step 1 Sleep(1000) ProgressSet($prog, $prog &"%") Next ProgressOff()Than he starts correctly with '0%' and not only with '%' and the next step is '1%' and not '0%' ...Looks a bit smoother ...GreetzCape-City Edited October 3, 2005 by Cape-City Link to comment Share on other sites More sharing options...
seandisanti Posted October 3, 2005 Share Posted October 3, 2005 Hmm that i don't know how to do...there was another similar topic about 2 weeks ago where i posted a script that watches for keystrokes or mouse movement to check inactivity. if you check my posts (click my name, then view user posts from the profile dropdown) you should be able to find it, if you want to add that functionality, i had just modified some script that gafrost had written for a diff purpose to have it check (with a loop) if any keys are pressed, and reset timer. Link to comment Share on other sites More sharing options...
Rex Posted July 26, 2007 Author Share Posted July 26, 2007 (edited) I just have updated the script, making it more presice... expandcollapse popup; 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 Edited July 28, 2007 by Rex Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now