Jump to content

How to check every 10 seconds that a window in the browser is active?


Recommended Posts

So  I want to write an endles loop that check that a window is active or not and if the window is not active it stops.

Sleep(5500)

$sActiveWindowTitle = WinGetTitle( "[ACTIVE]" ) 


$pagename = "Google"

ConsoleWrite(StringInStr($sActiveWindowTitle,$pagename))


While 1
    MyAdLibFunc()
WEnd

Func MyAdLibFunc()
 
    Local Static $iCount = 0
    $iCount += 1
    ConsoleWrite("MyAdLibFunc called " & $iCount & " time(s)" & @CRLF)

    If (StringInStr($sActiveWindowTitle,$pagename ) > 0)  Then

        ConsoleWrite(@CRLF & "now " & $sActiveWindowTitle & @CRLF)
        ConsoleWrite(StringInStr($sActiveWindowTitle,$pagename))


    Else
            
            ConsoleWrite(@CRLF & "now" & $sActiveWindowTitle & @CRLF)
            ConsoleWrite(StringInStr($sActiveWindowTitle,$pagename))
            
            Exit
    EndIf
EndFunc   ;==>MyAdLibFunc

 

Link to post
Share on other sites
  • Developers
1 minute ago, DannyJ said:

So  I want to write an endles loop that check that a window is active or not and if the window is not active it stops.

Nice, but what is the question/issue?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers

Ok, well, you aren't updating the $sActiveWindowTitle variable with the current situation so you keep on testing the start status. ;) 

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers
50 minutes ago, DannyJ said:

Thank you 

And have you got any idea how to update $sActiveWindowTitle variable?

Yes...  but more important have you? ;) 
You were able to fill it initially, so surely you can up we the appropriate statement at the right place to update that variable each loop you check for it.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

What Jos meant is you need to refresh the active window, take a look at this :

#include <Constants.au3>

Opt("MustDeclareVars", 1)

Const $pagename = "Google"

HotKeySet("{END}", "_Exit")
AdlibRegister("MyAdLibFunc", 10000); check every 10 secs

While 1
  Sleep(100)
WEnd

Func MyAdLibFunc()
  Local Static $iCount = 0
  $iCount += 1
  ConsoleWrite("MyAdLibFunc called " & $iCount & " time(s)" & @CRLF)

  Local $sActiveWindowTitle = WinGetTitle("[ACTIVE]")
  ConsoleWrite("now " & $sActiveWindowTitle & @CRLF)

  If StringInStr($sActiveWindowTitle, $pagename) Then
    ConsoleWrite(StringInStr($sActiveWindowTitle, $pagename & @CRLF))
  Else
    ConsoleWrite(StringInStr($sActiveWindowTitle, $pagename & @CRLF))
    Exit
  EndIf
EndFunc   ;==>MyAdLibFunc

Func _Exit ()
  Exit
EndFunc

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...