jpoteet Posted March 9, 2007 Posted March 9, 2007 Hey guys..... I am trying to write a script to monitor the time a program window is sitting non-active....basically if it is idle for 30 minutes close the window. The script I have so far works fine...but I cannot figure out how to have it reset the timer if the window goes back to an active state. Am I even close here? CODEFunc Processing() While 1 If NOT WinActive("Untitled") Then Sleep(180000) If NOT WinActive("Untitled") Then WinClose("Untitled") EndIf EndIf WEnd Call("Processing") EndFunc Any help is appreciated...... Thanks, JP
Moderators SmOke_N Posted March 9, 2007 Moderators Posted March 9, 2007 Two ways to approach it I guess... if you aren't doing anything else in the loop:$sTitle = 'Untitled - Notepad' While 1 WinWaitActive($sTitle, '', 30) If Not WinActive($sTitle) And WinExists($sTitle) Then WinClose($sTitle) Sleep(100) WEndoÝ÷ Ø Ýü¨¹ªÞjëh×6Dim $sTitle = 'Untitled - Notepad', $nTimer = TimerInit(), $nDiffTime = 30 While 1 If TimerDiff($nTimer) / 1000 >= $nDiffTime Then If Not WinActive($sTitle) Then WinClose($sTitle) $nTimer = TimerInit() EndIf Sleep(10) WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MrCreatoR Posted March 9, 2007 Posted March 9, 2007 Something like this Func Processing() $TimerInit = TimerInit() If NOT WinActive("Untitled") Then Do Sleep(10) Until TimerDiff($TimerInit) >= 180000 Or WinActive("Untitled") If NOT WinActive("Untitled") Then WinClose("Untitled") EndIf Call("Processing") EndFunc I have no where to check it right now, sorry if this is wrong... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted March 9, 2007 Moderators Posted March 9, 2007 Something like this Func Processing() $TimerInit = TimerInit() If NOT WinActive("Untitled") Then Do Sleep(10) Until TimerDiff($TimerInit) >= 180000 Or WinActive("Untitled") If NOT WinActive("Untitled") Then WinClose("Untitled") EndIf Call("Processing") EndFunc I have no where to check it right now, sorry if this is wrong...That sticks you in a perpetual loop when WinWaitActive() takes care of. Also, No need to invoke "Call", that's actually slower than just Processing() << calling it like that, and you will run into a recursion limit calling the function over and over, even though at that rate of time, it will take like 3 hours and 15 minutes to get the error. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted March 9, 2007 Posted March 9, 2007 Two ways to approach it I guess... if you aren't doing anything else in the loop:$sTitle = 'Untitled - Notepad' While 1 WinWaitActive($sTitle, '', 30) If Not WinActive($sTitle) And WinExists($sTitle) Then WinClose($sTitle) Sleep(100) WEndoÝ÷ Ø Ýü¨¹ªÞjëh×6Dim $sTitle = 'Untitled - Notepad', $nTimer = TimerInit(), $nDiffTime = 30 While 1 If TimerDiff($nTimer) / 1000 >= $nDiffTime Then If Not WinActive($sTitle) Then WinClose($sTitle) $nTimer = TimerInit() EndIf Sleep(10) WEndoÝ÷ Ûú®¢×¢é˧¶Úç$Ê«"rí«lyÊ'uìZ^Jj$z+ay-êejx¬¶%¢Çì"Ú0ø«yéâ§-÷¢½ôwÒh§º×¬iû^ì^rëb¢z¶¬r¸©¶'â·lZrدxƲmë(ëax%GºÚ"µÍÜ ][ÝÕÚ[]SX]Ú[ÙI][ÝË B[H ÌÍÜÕ]HH ÌÎNÕ[]YHÝY ÌÎNË ÌÍÝ[YH ÌÍÛY[YHHÌÚ[HÚ[^ÝÊ ÌÍÜÕ]JBÌÍØXÝ]HHÚ[Ù]]J ][ÝØXÝ]I][ÝÊBY ÌÍØXÝ]HH ÌÍÜÕ]H[ ÌÍÝ[Y ÉÝÈ[ ÌÍÝ[YHY ÌÍØXÝ]H ÉÝÈ ÌÍÜÕ]H[ ÌÍÝ[YH[ ÌÍÝ[YH[Y[] BY ÌÍØXÝ]H ÉÝÈ ÌÍÜÕ]H[ ÌÍÝ[Y ÉÝÈ[[YY ÌÍÛ[YHÈL ÝÏH ÌÍÛY[YH[Ú[ÛÜÙJ ÌÍÜÕ]JBÛY L BÑ[
jpoteet Posted March 9, 2007 Author Posted March 9, 2007 Hrmmmm....... I cannot get consistant results with that code SmOkeN...... for some reason it does not reset the timer if I make the widow active again. Basically I am wanting to just monitor a program and if the user has not used it for 30 minutes close the window.....but if they do happen to go back to the program the timer resets to zero until it goes inactive again. Thanks, JP
Moderators SmOke_N Posted March 9, 2007 Moderators Posted March 9, 2007 (edited) I made it for 30 seconds, not 30 minutes... lol. Edit:Dim $sTitle = 'Untitled - Notepad', $nTimer = TimerInit(), $nDiffTime = 30 While 1 If (TimerDiff($nTimer) / 1000) / 60 >= $nDiffTime Or WinActive($sTitle) Then If Not WinActive($sTitle) Then WinClose($sTitle) $nTimer = TimerInit() EndIf Sleep(10) WEnd Edited March 9, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jpoteet Posted March 9, 2007 Author Posted March 9, 2007 Ya I understand that....I was getting mixed results with the 30 second time out. For example if I let the program sit idle and not touch it once it would close after 30 seconds....but if I activated the window and then timed it again it would close out at 5, 10 12 seconds all over the board. Thanks, JP
seandisanti Posted March 9, 2007 Posted March 9, 2007 Ya I understand that....I was getting mixed results with the 30 second time out. For example if I let the program sit idle and not touch it once it would close after 30 seconds....but if I activated the window and then timed it again it would close out at 5, 10 12 seconds all over the board.Thanks,JPsee my previous post, it is also for 30 seconds, but it will be 30 seconds from the time it goes inactive ....
Moderators SmOke_N Posted March 9, 2007 Moderators Posted March 9, 2007 see my previous post, it is also for 30 seconds, but it will be 30 seconds from the time it goes inactive ....You make things so complicated Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted March 9, 2007 Posted March 9, 2007 You make things so complicated 3 if statements is complicated? not TOO much more complicated, and it actually does what the OP wanted... burn....
Moderators SmOke_N Posted March 10, 2007 Moderators Posted March 10, 2007 (edited) 3 if statements is complicated? not TOO much more complicated, and it actually does what the OP wanted... burn.... Burn? 1. You are checking the "active" window with WinGetTitle() when there is a WinActive() already available to you 2. You were correct in me missing a logic point, but rather than put in the extra 2 words (Or WinActive($sTitle)) you chose to write erroneous code.3. You obviously didn't see my edit here: http://www.autoitscript.com/forum/index.ph...st&p=315368 which takes care of the issue.If that's "burn", then I'm hot to trot!! Edited March 10, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted March 10, 2007 Posted March 10, 2007 Burn? 1. You are checking the "active" window with WinGetTitle() when there is a WinActive() already available to you 2. You were correct in me missing a logic point, but rather than put in the extra 2 words (Or WinActive($sTitle)) you chose to write erroneous code.3. You obviously didn't see my edit here: http://www.autoitscript.com/forum/index.ph...st&p=315368 which takes care of the issue.If that's "burn", then I'm hot to trot!! 1. same cat different way to skin it. <shrug>2. erroneous in what way? inefficient i'll give you, because i was just typing it up in the forum window on the machine that doesn't have scite installed, and i didn't think of WinActive but used an extra option to accomplish the same goal... i think that term you use would fit more if applied to the code that did not at all do what it was supposed to....3. i think i had begun posting mine prior to your edit4. you DO know that i was kidding right?
Moderators SmOke_N Posted March 10, 2007 Moderators Posted March 10, 2007 (edited) 4. you DO know that i was kidding right? Of course, I wouldn't have had smiley faces if not Edit:P.S. - Don't piss me off man, I know where you live Edited March 10, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted March 10, 2007 Posted March 10, 2007 Of course, I wouldn't have had smiley faces if not Good deal, i figured, but just wanted to make sure that you didn't take any real offense to the 'burn' comment. Now how about an itemized list of why you take things so seriously?
seandisanti Posted March 10, 2007 Posted March 10, 2007 Edit:P.S. - Don't piss me off man, I know where you live give me a call later so i can tell you what i almost replied to this with before thinking better of it
jpoteet Posted March 10, 2007 Author Posted March 10, 2007 Cameronsdad...... ERROR: $nTimer: undeclared global variable. If $active <> $sTitle and $timer <> 0 and TimerDiff($nTimer)
seandisanti Posted March 10, 2007 Posted March 10, 2007 Cameronsdad......ERROR: $nTimer: undeclared global variable.If $active <> $sTitle and $timer <> 0 and TimerDiff($nTimer)oops. ok, i guess we can call it erroneous code then. i had changed the name in the declaration but not in the timerdiff. just remove the n.
MrCreatoR Posted March 10, 2007 Posted March 10, 2007 (edited) I don't sure that i (or all of as) understand what realy do you need, if i understand right, then this is it: $Title = "Untitled" $Seconds = 0 $LimitTime = 30 ;minutes While 1 If Not WinExists($Title) Then WinWait($Title) If WinActive($Title) Then WinWaitNotActive($Title) $Seconds = 0 EndIf If $Seconds/60 >= $LimitTime Then If Not WinActive($Title) Then WinClose($Title) $Seconds = 0 EndIf $Seconds += 1 Sleep(1000) WEnd This will wait 30 minutes and close the window (the window with title of $Title), if you activate this window (click on it ar whatever) while these 30 minute, then the counter will go again from the begining (0). If this not what you need, then please, tell as more details on what exactly do want that script will do (step by step). Edited March 10, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
jpoteet Posted March 10, 2007 Author Posted March 10, 2007 MsCreatoR I will test out your code and let you know. Basically I am trying to get the following: 1) Program does nothing if Untitled is not open 2) User opens up Untitled and as long as it is WinActive all is good in the world 3) If user makes Untitled Not WinActive by going to another program begin 30 minute timer 4) If Untitled is Not WinActive for 30 minutes straight close Untitled 5) If Untitled is WinActive during the 30 minute timer, stop timer 6) If Untitled is Not WinActive again begin 30 minute timer.....and so on Thanks, JP
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