Jump to content
Sign in to follow this  
lolp1

WinExsist and how long it doesnt exsist question.

Recommended Posts

lolp1

Hello,

I need to make a main loop (as in doesn't stop, cause the window not existing for a X amount of time will happen many times)

So I need to be able to do all in a loop, Wait for the window to not exist, when it does not exsist start a timer, if that timer surpasses the "X" amount of time, then do my code. If the window exist again, set the timer to 0 and wait for the window to not exist again. Not sure how to do it, help appreciated.

(EDITED POST)

Edited by lolp1

Share this post


Link to post
Share on other sites
Davo

Hi, try this method:

$initialTime = TimerInit()
While Not WinExists("TitleOfWindowHere")
Sleep(100)
Wend
$finalTime = TimerDiff($initialTime)
MsgBox(0,"","Window Existed after: " & $finalTime & "milliseconds")

This will give you the time the window had not yet existed since you called the script.

Dave

Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
lolp1

Hi, try this method:

$initialTime = TimerInit()
While Not WinExists("TitleOfWindowHere")
Sleep(100)
Wend
$finalTime = TimerDiff($initialTime)
MsgBox(0,"","Window Existed after: " & $finalTime & "milliseconds")

This will give you the time the window had not yet existed since you called the script.

Dave

This does not accomplish the goal. This simple waits till the window does not exist to execute the code. I need to, when the window does not exsist for more then "X" time, then execute some code.

To give a English friendly example of whats needed..

if window does not exsist, for (X time) then do some code here.

EDIT: Also... I guess I could compare the time you gave above to the time I want, but once it runs the code, won't it exit the main loop?

Edited by lolp1

Share this post


Link to post
Share on other sites
star2

This will give you the time the window had not yet existed since you called the script.

Dave

nice jop Dave

this is my Suggestion

Sleep ( "your time here" )
If WinExists (  "your window here" ) Then
        your Command here
Else
        other Command when your window did not exist
EndIf

hope I could help

see ya


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites
Davo

This simple waits till the window does not exist to execute the code.

let me elaborate on the code so that you can understand

$initialTime = TimerInit() ;this is the time this line is called
While Not WinExists("TitleOfWindowHere") ;this loop will keep going until the window exists (pay close attention to the word "NOT")
Sleep(100)
Wend
$finalTime = TimerDiff($initialTime) ;this variable stores the time the window DID NOT exist
;now for the part you wanted that I didn't add because I thought it was quite obvious
Dim $time = x ;replace x with the time you want to wait
If $finalTime > $time Then
;execute some code
EndIf
Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
Davo

nice jop Dave

thanx your code is just as good to do the job :)

Dave


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
lolp1

I don't think I am clear on my goal.

I need to make a main loop (as in doesn't stop, cause the window not existing for a X amount of time will happen many times)

So I need to be able to all in a loop, Wait for the window to not exist, when it does not exsist start a timer, if that timer surpasses the "X" amount of time, then do my code. If the window exist again, set the timer to 0 and wait for the window to not exist again.

Share this post


Link to post
Share on other sites
Davo

If i have to elaborate any further I think I will probably end up elaborating on my own comments.

;This will keep looping until the Window no longer exists
While WinExists("titleOfTheWindowHere")
Sleep(100)
Wend

Then simply add the code I posted above to the bottom of this

Dave


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
lolp1

I guess I am just retarded because I don't see how your code accomplishes the goal.

The window will Exist and not exist allot. Meaning this code will need to be a non-stop loop, not just not exsist once and then execute my code and terminate the script.

I will need to be able to do this all non-stop (A non-stop loop...)

Keep checking for the Window not to exist ,when we've confirmed it does NOT exist, start the timer, and if the timer surpasses the time, to execute my code. (Which will make the window exist again) , and then start the whole thing all over again, as in waiting for the window not to exsist again. (Hence the loop). The code you provided:

$initialTime = TimerInit() ;this is the time this line is called // Only one time stamp..
While Not WinExists("TitleOfWindowHere") ;this loop will keep going until the window exists (pay close attention to the word "NOT")
Sleep(100)
Wend
// here it exits the loop, making it only work ONCE. <<<<<<<<<<<<


$finalTime = TimerDiff($initialTime) ;this variable stores the time the window DID NOT exist
;now for the part you wanted that I didn't add because I thought it was quite obvious
Dim $time = x ;replace x with the time you want to wait
If $finalTime > $time Then
;execute some code
EndIf
// The script would now End, I assume not accomplishing the goal. <<<<<<<<<<<<

As I said I may just not be getting something.

Edited by lolp1

Share this post


Link to post
Share on other sites
Davo

Ok thats a bit easier to understand what you need now and I can edit my code accordingly:

While 1
  While WinExists("titleOfTheWindowHere")
    Sleep(100)
  Wend
  $initialTime = TimerInit()
  Dim $time = x ;replace the time you want here in milliseconds
  While Not WinExists("TitleOfWindowHere")
    $finalTime = TimerDiff($initialTime)
    Sleep(100)
    If $finalTime > $time Then
      ExitLoop
    EndIf
  Wend
  ;do whatever code you want to do here for thsi condition
Wend

This code will go on forever :)

Dave

Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
lolp1

Ok thats a bit easier to understand what you need now and I can edit my code accordingly:

While 1
  While WinExists("titleOfTheWindowHere")
    Sleep(100)
  Wend
  $initialTime = TimerInit()
  Dim $time = x ;replace the time you want here in milliseconds
  While Not WinExists("TitleOfWindowHere")
    $finalTime = TimerDiff($initialTime)
    If $finalTime > $time Then
      ExitLoop
    EndIf
  Wend
Wend

This code will go on forever :)

Dave

Thanks, that makes alot more sense, I;ll test it out and post my results :)

Share this post


Link to post
Share on other sites
Davo

I edited the post, the code your are testing isn't right :) check the previous post to the one you just posted for the proper working code :)

Dave


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
lolp1

Works like a charm, thanks.

EDIT: I just did it like this to test, seemed to work fine...

While 1
  While WinExists($D2window) 
    Sleep(100)
Wend

  $initialTime = TimerInit();// Start the time stamp

  While Not WinExists($D2window)
    $finalTime = TimerDiff($initialTime)
    If $finalTime > $TimeWait Then
        
        _FileWriteLog("Log.txt","Worked... woot")
      ExitLoop
    EndIf
  Wend
Wend
Edited by lolp1

Share this post


Link to post
Share on other sites
Proph

Here's another idea...

CODE
While 1

If Not WinExists($D2window) Then _winFunc()

Sleep(10)

Wend

Func winFunc()

$initialTime = TimerInit();// Start the time stamp

While Not WinExists($D2window)

$finalTime = TimerDiff($initialTime)

If $finalTime > $TimeWait Then

_FileWriteLog("Log.txt","Worked... woot")

ExitLoop

EndIf

Wend

EndFunc

Edited by Proph

Share this post


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
Sign in to follow this  

×