Sign in to follow this  
Followers 0
Der_Andi

_IENavigate() steals focus from my other Apps

18 posts in this topic

Hi,

there's a script of mine running in the background. It has a embedded browser and navigates to some sites from time to time.

When i'm typing in notepad, for example, and the background-script performes the _IENavigate(), notepad is no longer the active window. The background-script is.

Any ideas how to prevent my background-script from being that thievish?

Andi

Share this post


Link to post
Share on other sites



Your problem is Internet Explorer. It tries to take over even when it doesn't need to. As a quick solution, just get the currently active window, then navigate, then activate the previously active window.

$window = WinGetTitle("")
;navigate in here
WinActivate($window)

Share this post


Link to post
Share on other sites

There is a hack built into _IENavigate designed to prevent this (and it is an issue with IE) - code came from Valik. It locks focus on the current active window before the _IENavigate and releases it after the _IENavigate. I have not seen it fail.

Make certain you are not running a very old version of IE.au3 (use (_IE_VersionInfo() ) and make certian you are not using the native .Navigate method instead of _IENavigate.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I tested Richards idea, but it is not working.

@DaleHohm: what "hack" do you mean? __IENavigate() (with 2 underscores) or __IELockSetForegroundWindow()?

The second function IS from Valik and does not work in my script, the __IENavigate is not from him and i haven't tested yet.

Share this post


Link to post
Share on other sites

I tested Richards idea, but it is not working.

@DaleHohm: what "hack" do you mean? __IENavigate() (with 2 underscores) or __IELockSetForegroundWindow()?

The second function IS from Valik and does not work in my script, the __IENavigate is not from him and i haven't tested yet.

__IELockSetForegroundWindow()

After some reflection, I recall that it is only _IECreate that usees the function. I've not seen an issue with Navigate causing this issue. Can you provide a reproducer?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I don't quite understand why what I posted wouldn't work. As simple as it is, I assumed it valid. I guess the call to navigate and the window focus change are asynchronous?

Share this post


Link to post
Share on other sites

Hi, I wrote a report "How to prevent internet explorer from stealing focus?" at May 10, 2007 in General Help and Support Forum. I have not received any comment yet may be I wrote it in the wrong forum.

I read some MSDN articles about IE stealing focus situations so I am suppose it a very complex theme which it is involving some IE bug. IE is stealing focus without any check about visible window's property.

Its a pity because its a limit for IE UDF develops applications solution.

Eduardo.

Share this post


Link to post
Share on other sites

Please supply a reproducer. I did some testing and I cannot create the behaviour you describe.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

He was saying that Internet Explorer will steal focus, even when it isn't being automated. I've seen it do it before. When you navigate to something and click into another window, sometimes Internet Explorer will freak out until you click it if it can't get take focus.

Share this post


Link to post
Share on other sites

Yes, I understand. I need a reproducer using IE.au3

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hi Dale.

I clean a main part of an original program in order to clarify our case.

The programs functionality is about request for retrieve patents. The espacenet engine response is get it on pages with 15 (or 30) records each one. The max number is 500 records for a request.

I prepare a reproducer program which it has an URL having a request criterion in order to get us more than 500 records (max) , so the program must navigate for 34 pages, having 15 records for pages or 17 pages having 30 each one.

You can run it, activate another windows application and you should see that for each page navigation event the focus on activates windows is stealing by IE navigation, even when the IE windows has visible property to off.

The function named Nav_Sgte is called whenever exist a next page on results. I has to insert some sentences around _IENavigate function trying to amend the focus stealing, but in fact I realize that it is not an stable or right solution so the program remain as beta version until now.

Regards,

Eduardo.

IE_stealing_focus.au3

Share this post


Link to post
Share on other sites

Hi Dale,

I tried to prepare a reproducer in a few yesterday, so I made some misstake on it while I built it from a main project. It has an endless logic. I hope you forgive me. I'm attaching a better version.

Anyway I think you should replicate the error.

Regards,

Eduardo.

IE_stealing_focus.au3

Share this post


Link to post
Share on other sites

Eduardo, can you narrow this down further? 300 lines of code with 10 include files makes a pretty huge scenario to work through, I would hope that you could get a reproducer down under 50 mines of code.

If the scenario is too complex to be able to cut back the code, then I need you to 1) give me specific instructions on how to run your code, 2) exactly what to watch for that demonstrates your trouble and 3) describe the exact flow through the code that is causing your trouble and when and how it occurs to the best of your knowledge.

I don't have the time to disect this much code line by line and try to understand what you are trying to do and where your trouble is -- I need your help.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hi Dale,

I'll try to clarify the reproducer. I am attaching a clean version. It is a simple program for navigation thought page resulting from engine espacenet patents request.

The reproducer program prepares an URL request to looking for patents having word hair in the title. The results are received on pages having until 15 links patents details.

1) You need an internet online connection in order to run it, you can open scite editor an press PF5.

2) After a few seconds, depending your internet connection speed, you will see that scite focus is lost, you can click on it or start any other window application and same behavior should be show you.

3) The start point is in _IENavigate ($oIE,$sgte) sentence on Nav_Sgte function. The fact is that navigation to next page event steal focus from any other activate windows even when visible property for IE windows is set to off.

Thanks for your concert about it.

Regards,

Eduardo.

IE_stealing_focus.au3

Share this post


Link to post
Share on other sites

I cannot reproduce this problem. It does not steal focus for me.

Can you cut this down to just the critical lines of code??? like:

$oIE = _IECreate(url)

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")

_IEAction($oIE, "invisible")
_IENavigate($oIE, newurl)
; Notepad should have lost focus

If so, we can have others test...

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Ok Dale, I did reproducer like you suggested and I got the same results.

The new reproducer version show the windows which it has focus after _IENavigate execution, which it was on IE window "esp@cenet vista de resultados - Microsoft Internet Explorer" and not on Notepad windows as we expected.

Regards,

Eduardo.

IE_stealing_focus.au3

Share this post


Link to post
Share on other sites

Notepad never loses focus for me, sorry.

BTW, I really meant, can't you cut your example down to 6 lines of code? Then we can have others test. There showld be no need to have all of the detail of what you are doing with serching page content etc -- it just gets in the way of the issue you are trying to demonstrate.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Ok.

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