Jump to content

Program Timer for WinActive?


Recommended Posts

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?

CODE
Func 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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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Ñ[
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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 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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

see my previous post, it is also for 30 seconds, but it will be 30 seconds from the time it goes inactive ....
Link to comment
Share on other sites

  • Moderators

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 :whistle:

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.

Link to comment
Share on other sites

  • Moderators

3 if statements is complicated? not TOO much more complicated, and it actually does what the OP wanted... burn.... :whistle:

Burn? :D

1. You are checking the "active" window with WinGetTitle() when there is a WinActive() already available to you :lmao:

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!! :P

Edited 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.

Link to comment
Share on other sites

Burn? :D

1. You are checking the "active" window with WinGetTitle() when there is a WinActive() already available to you :lmao:

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!! :P

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 edit

4. you DO know that i was kidding right?

:whistle:

Link to comment
Share on other sites

  • Moderators

4. you DO know that i was kidding right?

:whistle:

Of course, I wouldn't have had smiley faces if not :D

Edit:

P.S. - Don't piss me off man, I know where you live :P

Edited 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...