Borje Posted December 9, 2008 Share Posted December 9, 2008 (edited) Hello Is it poosible to change this script to Disconnect and Connect to Internet I have done som tests but can not find a solution to have this outside the loop. I want when computer is idle that should disconnect from the Internet and when I move the mouse again it would Connect to the Internet again. Is there any solution to have this _RunDOS("ipconfig /release") ; Disconnect Internet running one time when idle time is up? and have this _RunDOS("ipconfig /renew") ; Connect to Internet running one time when I move the mouse? I have done some tests but cannot have this to working ouside the loop. Please can anybody help me to fix so this working outside the loop? I can not find any solution. I have try and try I have much to learn me!! Code: #include <Process.au3> $Idle = 0 $Old = MouseGetPos() While 1 $Get = MouseGetPos() If $Get[0] = $Old[0] And $Get[1] = $Old[1] Then $Idle += 1 Else $Idle = 0 EndIf If $Idle <> 0 Then TrayTip("", "Idle time : " & $Idle & " second.", 1, 16) Else TrayTip("", "Hello", 0) EndIf $Old = MouseGetPos() Sleep(1000) WEnd ;_RunDOS("ipconfig /release") ; Disconnect Internet ;_RunDOS("ipconfig /renew") ; Connect Internet Edited December 10, 2008 by Borje Link to comment Share on other sites More sharing options...
Andreik Posted December 9, 2008 Share Posted December 9, 2008 (edited) You try to detect moves of mouse but if I press a key? This is a good function to get idle time: Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Edited December 9, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Borje Posted December 9, 2008 Author Share Posted December 9, 2008 (edited) Thanks Andrejk, I would like a example to that code I post and I need some example code. Edited December 9, 2008 by Borje Link to comment Share on other sites More sharing options...
Borje Posted December 9, 2008 Author Share Posted December 9, 2008 Is there anybody out there can give me some code example that I ask in my first post what i must do to have that to work outside the loop? Link to comment Share on other sites More sharing options...
martin Posted December 9, 2008 Share Posted December 9, 2008 Is there anybody out there can give me some code example that I ask in my first post what i must do to have that to work outside the loop?I think you mean this sort of thing, but I'm not sure. expandcollapse popup#include <Process.au3> $Idle = 0 $Old = MouseGetPos() $internet = true;assume we start with internet connected $maxCount = 500;how long to wait before turning off internet connection While 1 $Get = MouseGetPos() If $Get[0] = $Old[0] And $Get[1] = $Old[1] Then $Idle += 1 $Old[0] = $Get[0] $Old[1] = $Get[1] Else $Idle = 0 EndIf If $Idle <> 0 Then TrayTip("", "Idle time : " & $Idle & " second.", 1, 16) if $Idle > $MaxCount and $internet = true Then abcd();turn off $Internet = false EndIf Else TrayTip("", "Hello", 0) EndIf if $Idle < $MaxCount and $internet = false Then defg();turn on $interney = True EndIf Sleep(1000) WEnd Func abcd() ;; EndFunc Func defg() ; ; EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Borje Posted December 14, 2008 Author Share Posted December 14, 2008 Thanks Martin this worked great and thanks to others to. 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