ComObjConnect/IE question

Get help with using AutoHotkey and its commands and hotkeys
Miguel7
Posts: 168
Joined: 08 Sep 2014, 07:06

ComObjConnect/IE question

27 Jul 2016, 13:32

Hi guys,

So I've been trying to figure out a way to call AHK code when a user clicks a button or link in an IE window, *without* using an embedded AHK GUI. The reason I'm trying to avoid embedding IE in a GUI is it seems to break keyboard navigation (and accessibility is an important part of this project - and every project IMO but especially here). Pressing Tab seems to move the focus outside the embedded browser and into... something else. So that's not going to work here. So here's what I've got so far...

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Then when I restart or exit the script, I get any number of cryptic errors (ranging from "the interface is unknown" to "object invoked disconnected from blah blah deeblahdee blah" - lol). So I'm obviously missing something, gotta be something slight'n'stupid (as most bugs are) but so far it's code 1 me 0. lol idk - any clues would be greatly appreciated.
Guest

Re: ComObjConnect/IE question

27 Jul 2016, 14:04

https://autohotkey.com/boards/viewtopic.php?t=1267

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Miguel7
Posts: 168
Joined: 08 Sep 2014, 07:06

Re: ComObjConnect/IE question

27 Jul 2016, 14:25

Wow, thanks for the quick response on this! But how would it work with a local file? Does it require the full file:// address? Because for example if I try A_ScriptDir . "\test.html" it throws a tantrum. First it doesn't like "busy" and then it doesn't like "document" and then it says there's no valid COM object... any guesses? Thanks again.

EDIT: Tried with the full file:// address with no %variables% - still has kittens.
Guest

Re: ComObjConnect/IE question

27 Jul 2016, 14:36

That's strange.
The below code works for me when pointed local. Does the full file location work for you?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Miguel7
Posts: 168
Joined: 08 Sep 2014, 07:06

Re: ComObjConnect/IE question

27 Jul 2016, 14:49

No dice. I had to change the file path/name, but apart from that I kept it exactly as you showed me. But it's still coughing up the same 3 errors:

First: it screams about "busy"...

---------------------------
test.ahk
---------------------------
Error: 0x80004005 - Unspecified error

Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0

Specifically: busy

Line#
006: wb := ComObjCreate("InternetExplorer.Application")
007: wb.visible := True
008: wb.Navigate("C:\Users\mfox\Desktop\test.html")
---> 009: While,wb.busy
010: Sleep,100
011: doc := wb.document
012: ComObjConnect(doc, "Doc_")
013: Gui,Show
014: Return
017: ExitApp
019: {

Continue running the script?
---------------------------
Yes No
---------------------------

If I click "yes", it spits this:
---------------------------
test.ahk
---------------------------
Error: 0x80010108 - The object invoked has disconnected from its clients.


Specifically: document

Line#
006: wb := ComObjCreate("InternetExplorer.Application")
007: wb.visible := True
008: wb.Navigate("C:\Users\mfox\Desktop\test.html")
009: While,wb.busy
010: Sleep,100
---> 011: doc := wb.document
012: ComObjConnect(doc, "Doc_")
013: Gui,Show
014: Return
017: ExitApp
019: {
020: MsgBox,doc.parentWindow.event.srcElement.OuterHtml
021: }

Continue running the script?
---------------------------
Yes No
---------------------------

And if I hit Yes again, it pukes this:
---------------------------
test.ahk
---------------------------
Error: No valid COM object!

Line#
006: wb := ComObjCreate("InternetExplorer.Application")
007: wb.visible := True
008: wb.Navigate("C:\Users\mfox\Desktop\test.html")
009: While,wb.busy
010: Sleep,100
011: doc := wb.document
---> 012: ComObjConnect(doc, "Doc_")
013: Gui,Show
014: Return
017: ExitApp
019: {
020: MsgBox,doc.parentWindow.event.srcElement.OuterHtml
021: }
022: Exit

Continue running the script?
---------------------------
Yes No
---------------------------
If I hit Yes again, the dumb thing finally shuts up but doesn't work (which makes sense, since it just finished spewing a ton of errors, lol) but idk what the heck could possibly be bugging things up this bad.

But I have an idea of an alternate approach: if I were to go with the GUI, is there a way to prevent the focus from leaving the embedded browser (so Tab and Shift-Tab behave like they normally would in IE, instead of going into GUI-limbo)? Just wondering because most of the posts I've read nowadays seem to go the GUI route, and even I've been able to embed an HTML file in a GUI... so maybe there's some trick out there I'm just not aware of yet. :)
Guest

Re: ComObjConnect/IE question

27 Jul 2016, 15:44

I'm not sure why you are getting so many errors. I can run the script with the webpage embedded in a GUI or not embedded. I am running Win7 64bit on IE 11 with admin privileges.
gongnl
Posts: 69
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

Re: ComObjConnect/IE question

20 Mar 2017, 16:45

bump,i have same problem,who help me?thank
A_AhkUser
Posts: 260
Joined: 06 Mar 2017, 16:18
Location: France

Re: ComObjConnect/IE question

20 Mar 2017, 17:15

Invité wrote:I'm not sure why you are getting so many errors. I can run the script with the webpage embedded in a GUI or not embedded. I am running Win7 64bit on IE 11 with admin privileges.


for sure it's work.
just tried it out with a badly written html:
<
<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />
<title>HTMLFile</title>
</head>
<body>
<span class="X" style="display: none;"></span>
<div class="C" style="padding: 15px;">
</div>
</body>
</html>

and it give me the same error code as you miguel: 0x800004005

so it's probably your html code


EDIT:

miguel7 wrote: the full file://


the full is file:///
Miguel7
Posts: 168
Joined: 08 Sep 2014, 07:06

Re: ComObjConnect/IE question

25 Mar 2017, 11:02

Thanks, but I stopped using IE ages ago. Instead I've been using NW.js (a framework for creating desktop apps using HTML/JS/CSS). NW makes it possible to run AHK scrpts right from the DOM, and capture any input from stdout (i.e. if you type "FileAppend, someData, *" in AHK then run it from NW it will return "someData"). If you are still getting whatever error this was about, you might want to check it out.

Return to “Ask For Help”

Who is online

Users browsing this forum: MaxAstro, Railang and 33 guests