The problem is I'm stuck at communicating synchronously between the browser (ActiveX IE) and the wrapper (AHK).
Firstly, I know we can react to events inside the browser using the ComObjConnect method. See the bare minimum code below:
Upon user event:
Code: Select all
Gui Add, ActiveX, w800 h600 vwb, Shell.Explorer
wb.Navigate("about:blank")
wb.document.write("<input type='button' id='btn' value='Say Hi!'>")
btn := wb.document.All.btn
ComObjConnect(btn, "btn_")
btn_onclick() {
MsgBox, AHK says Hi!
}
Gui Show
Code: Select all
Gui Add, ActiveX, w800 h600 vwb, Shell.Explorer
wb.Navigate("about:blank")
ComObjConnect(wb, new wb_events)
wb.document.write("<script>document.location.href='#hello';</script>")
class wb_events {
__Call(p*) {
if (p[1] == "BeforeNavigate2") {
MsgBox, AHK says Hi!
}
}
}
Gui Show
That would allow the following code in Javascript:
line 1: window.test = 1;
line 2: API.callAHK(); // here AHK applies a change of value on "window.test"
line 3: alert(window.test); // JS outputs a different value (not 1)
Things I have tried:
- Triggering a browser event (let's say "BeforeNavigate2") and hoping AHK catches it before the next line of code in JS. It did't, it caught it after a few miliseconds.
- Manually triggering the "click" event of an element that AHK has hooked. I had high hopes for this, because in Javascript the events are triggered instantaneously, even before the next line of code is processed. However, the manual trigger DID NOT arrive in AHK! See sample code below, which uses the modern IE engine:
Code: Select all
FixIE(true) Gui Add, ActiveX, w800 h600 vwb, Shell.Explorer wb.Navigate("about:blank") blob = ( <script> function manualTrigger(){ var evt = document.createEvent('MouseEvents'); evt.initEvent("click", true, true); document.getElementById('btn').dispatchEvent(evt); } </script> <input type='button' id='btn' onclick='alert("JS says Hi!")' value='BUTTON'> <input type='button' onclick='manualTrigger()' value='BUTTON'> ) wb.document.write(blob) btn := wb.document.All.btn ComObjConnect(btn, "btn_") btn_onclick() { MsgBox, AHK says Hi! } Gui Show ;http://www.autohotkey.com/board/topic/93660-embedded-ie-shellexplorer-render-issues-fix-force-it-to-use-a-newer-render-engine/ FixIE(Apply=True, Version="", ExeName="") { static Key := "Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION" , Versions := {7:7000, 8:8888, 9:9999, 10:10001, 11:11001} if !(Version := Versions[Version]) Version := 0 ; Disable browser emulation if !ExeName { if A_IsCompiled ExeName := A_ScriptName else SplitPath, A_AhkPath, ExeName } if Apply RegWrite, REG_DWORD, HKCU, %Key%, %ExeName%, %Version% else RegDelete, HKCU, %Key%, %ExeName% }
Code: Select all
Gui Add, ActiveX, w800 h600 vwb, Shell.Explorer
wb.Navigate("about:blank")
wb.document.write("<script>window.test = function(){alert('JS says Hi!');}</script><input type='button' onclick='test()' value='Say Hi!'>")
wb.document.parentwindow.test := Func("hello")
hello(){
MsgBox, AHK says Hi!
}
Gui Show