Sign in to follow this  
Followers 0
ch1234

Adlib function help

22 posts in this topic

I'm trying to run a script but there's an annoying pop-up window that shows up intermittently that causes my script to stop working (it can't handle the popup). I did a bit of research and I see there's an AdlibRegister function that can check for a condition and then act on that condition which is perfect for me....but I can't get it to work.

I want the Adlib function to check if a message box is active, and if it is, to close it (either by sending 'enter' or moving the mouse to certain coordinates). I can do the latter part easily but getting the Adlib function to work is where I'm running into trouble.

I register the Adlib function normally and then inside the declaration, I have something like

If WinActive("Error") Then MouseClick("left", 200, 300, 1, 0) EndIf

Any advice? (Thanks in advance)

P.S. I've also experimented with changing the name of the pop-up box from "Error" to some pop up box I cause to appear (eg "Test") and it still doesn't work.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this should work:

AdlibRegister("check", 250)
 

While 1
 sleep(100)
WEnd
 
Func check()
If WinActive("Error") Then WinClose("Error", "")
EndFunc

If that is not working, I would revisit the pop up and use the AutoIt window info tool to gather more data.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Don't use MouseClick, use ControlClick to click away the pop up window.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks for all the help so far! I'll check it out later when I get a chance.

Something like this should work:

AdlibRegister("check", 250)


While 1
sleep(100)
WEnd

Func check()
If WinActive("Error") Then WinClose("Error", "")
EndFunc

If that is not working, I would revisit the pop up and use the AutoIt window info tool to gather more data.

I've a question about this - I don't really understand this part:

While 1
sleep(100)
WEnd

Do I need this if I have a program written already that iterates in a loop?

Share this post


Link to post
Share on other sites

You can drop the mentiond While loop and replace it with your code. The example code is just to make sure that the script doesn't end immediately and the Sleep is to prevent the CPU to run at 100%.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What he said ^^^^ :) Sorry, I should have explained that better


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Sorry to bother you again, that's still not working the way I want it to. I can get it to run if I create 2 separate scripts and run them simultaneously but I don't really want to do that - I'd rather have it all in the one script.

This is the sample code I've written to test it:

AdlibRegister("MyAdlib",50)

Func MyAdlib()
If WinActive("Tutorial") Then WinClose("Tutorial", "")
EndFunc

MsgBox(0, "Tutorial", "Hello World!")
While 1
sleep(100)
WEnd

Taking the MsgBox line out and placing it into another script will execute the program correctly but I'd rather have it in the one file. Do I have to create threads to do this?

Share this post


Link to post
Share on other sites

You need to explain what you mean by "not working the way I want it to", we can't read your mind :) Your script, as written, does just what it looks like - It registers the AdLib function, then brings up a MessageBox. Once the message box is closed, it sleeps until the windows Tutorial is active, and then closes it. What more do you want?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

ch1234,

This works

#include <GUIConstantsEx.au3>
AdlibRegister("MyAdlib",500)
Func MyAdlib()
If WinActive("Tutorial") Then WinClose("Tutorial", "")
EndFunc
guicreate('Tutorial')
guisetstate()
;MsgBox(0, "Tutorial", "Hello World!")
While guigetmsg() <> $gui_event_close
WEnd

When the adlib run frequency is changed to "50" it does NOT work. Don't know why. Also, I think that if you look at msgbox with one of the window inspection tools you will find that the title is not what you think, however, just speculating as I have never used this function before.

kylomas

edit: clarity - I don't use the windows automation functions, of course I've used msgbox

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Not sure why the OP needs all the extra, unless (as I asked for clarification) he is doing more that he is not explaining. The code he posted in #8 worked fine for what he stated he wanted to do, even with a frequency of 50. I believe there is simply more to it that has not been properly explained.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

JLogan3o13,

Agreed, although when I change the value in the code that I posted to 50 ms the script hangs.

kylomas

edit: Do you know that the code in #8 worked...the msgbox was actioned by a button or control, was it not?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

JLogan3o13,

You're right. When I run this

#include <GUIConstantsEx.au3>

AdlibRegister("MyAdlib",50)

Func MyAdlib()
If WinActive("Tutorial") Then WinClose("Tutorial", "")
EndFunc

guicreate('Tutorial')
guisetstate()

MsgBox(0, "Tutorial", "Hello World!")
While guigetmsg() <> $gui_event_close
WEnd
it works exactly as expected. I think that the OP is expecting the winwait winactive to act on the msgbox, however.

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Adlib seems to pause during a Msgbox() function.

Try this and listen to the output.

AdlibRegister("MyAdlib")
Func MyAdlib()
Beep(1000, 150)
EndFunc ;==>MyAdlib

Sleep(2000)
MsgBox(262144, "Msgbox ", "First Msgbox is active", 2)
Sleep(2000)
MsgBox(262144, "Msgbox ", "Second Msgbox is active", 2)
Sleep(1000)
Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Hi guys, thanks for the help again. I haven't been near my computer with the script on it yet to try test out your suggestions but I'll try offer some more clarity to the problem I'm having.

I've written a script to click the left mouse button every few seconds to keep a window active but every now and then a message box will pop up and my script doesn't do anything to account for this new message box - it'll keep trying to click in the same spot and eventually the session will time out. I want to use the adlib function to pause my main script, send a command to close the pop up message box, and then resume the main script again - preferably all in a single .au3 file.

In the code I tested above, the adlib function wouldn't close the pop up message box if the adlib function was in the same script that created the message box. However, if I moved the into separate scripts it worked fine. This is where I don't understand what's going on and why the adlib function won't work in the same script that creates the message box.

Thanks again.

Share this post


Link to post
Share on other sites

Hi, ch1234. What is the program window you're trying to keep active? Depending on the type of application (Windows GUI, Java, web-based), there may be much easier ways of doing this.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

ch1234,

The msgbox is blocking script functions as demonstrated by the following

#include <GUIConstantsEx.au3>
GUICreate('Tutorial')
GUISetState()
AdlibRegister("MyAdlib", 1000)
MsgBox(0, "MSG1", "Hello World!")
While GUIGetMsg() <> $gui_event_close
WEnd

Func MyAdlib()
    ConsoleWrite('trying to close msg box' & @LF)
    If WinActive("MSG1") Then WinClose("MSG1", "")
EndFunc   ;==>MyAdlib

Run the code. The adlib message does NOT appear until you close the msgbox.

You may be able to use a simple gui to mimic a msgbox, or persue this from the applications end, as suggested by JLogan3o13

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

hi, please try this

$a=WinGetTitle("")

If($a=="Error") Then

MouseClick("left", 200, 300, 1, 0)

EndIf

Share this post


Link to post
Share on other sites

Hi, ch1234. What is the program window you're trying to keep active? Depending on the type of application (Windows GUI, Java, web-based), there may be much easier ways of doing this.

It's a Java app.

ch1234,

The msgbox is blocking script functions as demonstrated by the following

#include <GUIConstantsEx.au3>
GUICreate('Tutorial')
GUISetState()
AdlibRegister("MyAdlib", 1000)
MsgBox(0, "MSG1", "Hello World!")
While GUIGetMsg() <> $gui_event_close
WEnd

Func MyAdlib()
    ConsoleWrite('trying to close msg box' & @LF)
    If WinActive("MSG1") Then WinClose("MSG1", "")
EndFunc ;==>MyAdlib

Run the code. The adlib message does NOT appear until you close the msgbox.

You may be able to use a simple gui to mimic a msgbox, or persue this from the applications end, as suggested by JLogan3o13

kylomas

Thanks for that. I won't be able to run it until the weekend but I'll give it a try then!

Share this post


Link to post
Share on other sites

Sorry to resurrect an old thread. I haven't had a chance to get back to this in a good while (it's a project of mine). I tried to run the Adlib function as suggested and it worked fine, thanks everyone.

However, I'm still having trouble dealing with this annoying Java popup window - it completely breaks my script every time. I can close the window manually by pressing enter but that requires me to sit there and wait for it to popup which is useless. I tried adding an enter keypress into the script but it won't work as the timing has to be precise and the window pops up infrequently and with no discernible patterns. Since it's part of the Java app, it doesn't show up in Task Manager so I can't find the name of the window.

Any suggestions?

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  
Followers 0