SkellySoul Posted June 21, 2009 Share Posted June 21, 2009 How can I find out when the computer is idle (both mouse and keyboard) I know _Timer_GetIdleTime() does exactly that but the problem is I got a tray menu and if the user pushes something on the menu it won't work since it's checking if the computer is idle or not Basically what I want done is when the mouse and keyboard are idle it will shut off the internet connection and than in the tray menu there will be a option to turn it back on. ;#NoTrayIcon #include <NetCC.au3> #include <Timers.au3> #Include <Constants.au3> Opt("TrayMenuMode" , 1) $Exit = TrayCreateItem("Exit") $Connection = 1 While 1 $Msg = TrayGetMsg() Select Case $Msg = $Exit Exit EndSelect WEnd ;Func _Idle($iSleep) ; If _Timer_GetIdleTime() >= $iSleep Then ; TrayTip("Connection..." , "connection being shut off..." , 2) ; _NetCC("ALL", 0) ; $Connection = 0 ; EndIf ;EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 (edited) How can I find out when the computer is idle (both mouse and keyboard) I know _Timer_GetIdleTime() does exactly that but the problem is I got a tray menu and if the user pushes something on the menu it won't work since it's checking if the computer is idle or not Basically what I want done is when the mouse and keyboard are idle it will shut off the internet connection and than in the tray menu there will be a option to turn it back on. ;#NoTrayIcon #include <NetCC.au3> #include <Timers.au3> #Include <Constants.au3> Opt("TrayMenuMode" , 1) $Exit = TrayCreateItem("Exit") $Connection = 1 While 1 $Msg = TrayGetMsg() Select Case $Msg = $Exit Exit EndSelect WEnd ;Func _Idle($iSleep) ; If _Timer_GetIdleTime() >= $iSleep Then ; TrayTip("Connection..." , "connection being shut off..." , 2) ; _NetCC("ALL", 0) ; $Connection = 0 ; EndIf ;EndFunc You can add the tray menu item to turn it back on, but this AdLib function should take care of turning it off: #include <NetCC.au3> #include <Timers.au3> #include <Constants.au3> Opt("TrayMenuMode", 1) Global $Exit = TrayCreateItem("Exit") Global $Connection = 1 Global $iSleep = 30 * 60 * 1000; 30 minutes in milliseconds AdlibRegister("_Idle", 1000); Check every 1 second While 1 $Msg = TrayGetMsg() Select Case $Msg = $Exit Exit EndSelect WEnd Func _Idle($iSleep) If $Connection Then If _Timer_GetIdleTime() >= $iSleep Then TrayTip("Connection...", "connection being shut off...", 2) _NetCC("ALL", 0) $Connection = 0 EndIf EndIf EndFunc ;==>_Idle Edit: Grammar. Edited June 22, 2009 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
SkellySoul Posted June 22, 2009 Author Share Posted June 22, 2009 You can add the tray menu item to turn it back on, but this AdLib function should take of turning it off: #include <NetCC.au3> #include <Timers.au3> #include <Constants.au3> Opt("TrayMenuMode", 1) Global $Exit = TrayCreateItem("Exit") Global $Connection = 1 Global $iSleep = 30 * 60 * 1000; 30 minutes in milliseconds AdlibRegister("_Idle", 1000); Check every 1 second While 1 $Msg = TrayGetMsg() Select Case $Msg = $Exit Exit EndSelect WEnd Func _Idle($iSleep) If $Connection Then If _Timer_GetIdleTime() >= $iSleep Then TrayTip("Connection...", "connection being shut off...", 2) _NetCC("ALL", 0) $Connection = 0 EndIf EndIf EndFunc ;==>_Idle I didn't think of doing it like that I figured that would just restart it over and over again because I figured _Timer_GetIdleTime() was just sort of like the sleep function. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2009 Share Posted June 22, 2009 I didn't think of doing it like that I figured that would just restart it over and over again because I figured _Timer_GetIdleTime() was just sort of like the sleep function.Then you didn't read the description of the function in the help file, or understand how the example script there works. 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 Link to comment Share on other sites More sharing options...
Yeik Posted June 22, 2009 Share Posted June 22, 2009 You know, you dont have to repost every 15 minutes. I actualy think your probably hitting refresh or F5 and hitting yes to resend the data, which makes your browser think that it is doing the same post over, and sends it to the server. func get_quote() local $quote switch random(1, 3, 1) case 1 $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _ "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _ "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _ "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein" case 2 $quote = '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _ "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)" case 3 $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein" EndSwitch MsgBox(0, "Quote for the moment", $quote & @CRLF) EndFunc get_quote() Link to comment Share on other sites More sharing options...
SkellySoul Posted June 22, 2009 Author Share Posted June 22, 2009 (edited) Then you didn't read the description of the function in the help file, or understand how the example script there works. oh ok I get how it works now... one other stupid question if you don't mine this is the code I got so far now. The problem is when I click on "Connection On/Off" it sets $TRAY_CHECKED/$TRAY_UNCHECKED I don't want it to be checked at all I just want it to run the function without setting the state of me clicking the tray and sometimes when I hit the "Exit" in the tray it will add a check mark and not exit until I hit it again expandcollapse popup#include <Misc.au3> #include <NetCC.au3> #include <Timers.au3> #include <Constants.au3> Opt("TrayMenuMode", 1) Global $Connection , $ConnectToggle , $iSleep = 10000 _Singleton(@ScriptName , 0) $ConnectToggle = TrayCreateItem("Connection On/Off") $Exit = TrayCreateItem("Exit") AdlibRegister("_Idle", 1000) While 1 $Msg = TrayGetMsg() Select Case $Msg = $Exit Exit Case $Msg = $ConnectToggle If $Connection = 1 Then _NetCC("ALL", 0) $Connection = 0 ElseIf $Connection = 0 Then _NetCC("ALL", 1) $Connection = 1 Else Exit EndIf EndSelect WEnd Func _Idle($iSleep) If $Connection Then If _Timer_GetIdleTime() >= $iSleep Then TrayTip("Connection...", "Connection being shut off...", 2) _NetCC("ALL", 0) $Connection = 0 EndIf EndIf EndFunc Edited June 22, 2009 by SkellySoul 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