KaFu Posted March 4, 2009 Share Posted March 4, 2009 (edited) HiHo, in course of investigating how to use SMF's idle time for background update activity I came up with the following solution. The program is considered idle after x ms of inactivity (mouse AND keyboard) OR if none of the program's windows are active. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Timers.au3> #include <WinAPI.au3> Local $msg Global $bIdle = false Global $iIdle_Time = 10000 ; program considered idle after x ms of inactivity (mouse AND keyboard) OR if none of the programs windows are active $hGUI = GUICreate("Idle Time Test-GUI",300,100,100,100,Default,$WS_EX_TOPMOST) $label = GUICtrlCreateLabel("NOT Idle...",10,10,200) $label2 = GUICtrlCreateLabel("",10,40,200,20) GUISetState(@SW_SHOW) $hTimer_IdleCheck = _Timer_SetTimer($hGUI, 1000, "__Timer_IdleChecker") ; check if program is idle / NOT idle every x ms... $hGUIchild = GUICreate("Idle Time Test-GUI Child",300,100,500,100,Default,$WS_EX_TOPMOST) ; child GUI to demonstrate check of none of the programs windows are active GUISetState(@SW_SHOW) While 1 sleep(10) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop if $bIdle = true Then GUICtrlSetData($label, "Idle...") while $bIdle = true ; Do something if idle... ; here be more code ; ... sleep(100) ; for more complex / lengthly operations / loops insert something like if $bIdle = true then exitloop GUICtrlSetData($label2,TimerInit()) wend GUICtrlSetData($label, "NOT Idle...") endif WEnd GUIDelete() func __Timer_IdleChecker($hWnd, $Msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime if @AutoItPID <> WinGetProcess(_WinAPI_GetAncestor(WinGetHandle("[ACTIVE]"), $GA_ROOTOWNER)) then ; none of the programs windows are active $bIdle = true Else if _Timer_GetIdleTime() > $iIdle_Time Then ; program considered idle after x ms of inactivity $bIdle = True Else $bIdle = False endif endif EndFunc Maybe useful to someone else, or maybe someone has ideas how to improve this one ... Best Regards Edited March 4, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
bhyde1984 Posted March 24, 2009 Share Posted March 24, 2009 This is an incredible script! I'm blown away that no one has commented so I signed up for an account just to comment on this posting! I modified the script slightly to fit my needs but this thing is great! I wrote a script that disables the wireless network adapter if the wired adapter is active but had issues with it pulling CPU usage all the time. This script was the perfect fix! I worked it into my existing script and now if the mouse and/or keyboard don't move for 1 second, then the script pauses. It's great! Thanks again for the great posting! Link to comment Share on other sites More sharing options...
KaFu Posted March 25, 2009 Author Share Posted March 25, 2009 (edited) Thanks for the nice feedback ... In my current script I embed some long running functions in this _Timer_KillTimer($gui_SMF_Search_Main, $gui_SMF_Search_Main_Timer_IdleCheck) ;.... long running function $gui_SMF_Search_Main_Timer_IdleCheck = _Timer_SetTimer($gui_SMF_Search_Main, $iIdle_CheckTime, "__Timer_IdleChecker") to deactivate the check while running, but otherwise I didn't found any further improvement possibilities yet. What did you tweak? Best Regards Edited March 25, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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