Jump to content

Adlib function help


ch1234
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

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

  • 1 month later...

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?

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