从IE / JavaScript COM捕获事件信息

时间:2016-01-10 02:26:09

标签: internet-explorer events com autohotkey

所以我设法在现有的IE窗口中注册了一个mousemove事件,但是每次调用我的函数时,我都没有得到你通常用Javascript获得的事件信息。例如,mousemove事件应该将有关当前鼠标位置的信息发送到回调函数。

这基本上就是我正在做的事情:

window.call___back := Func("msg")
window.addEventListener("mousemove",window.call___back)

msg(e:="") {
    TrayTip, Mouse position on page, % "x: " e.pageX "`ny: " e.pageY
}

TrayTip从不显示任何坐标,我假设e根本没有发送到该功能。

知道我怎么能得到丢失的事件信息? (我对使用JavaScript获取信息感兴趣。它必须是AHK函数。)

到目前为止,这是整个脚本: (打开IE窗口,导航到网站,确保窗口处于活动状态,按F3并将鼠标移到页面上。)

#Persistent
active:={ie:IeGet()}
ActiveIeMonitorWithParam := Func("ActiveIeMonitor").Bind(active)
SetTimer, % ActiveIeMonitorWithParam, 100

width := 400
height := 200
Gui, +AlwaysOnTop +hwndHWND
Gui, Add, Edit, vGUI_InfoBox w%width% h%height%
Gui, Show, % "x" A_ScreenWidth-width-30 " y" 5, Bruttos iWB2 Learner
WinSet, Transparent, 200, ahk_id %HWND%

Return

F3::
    IE := active.ie
    If !ComObjType(IE,"IID")
        Return
    doc := IE.document
    document := doc.documentElement
    window := ComObj(9,ComObjQuery(IE,"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"),1)
    info := "Title: " doc.title "`n"
    info .= "Url: " IE.locationUrl "`n"

    ;window.eval("alert('injected javascript!');")
    ;window.eval("window.addEventListener('click',call___back);")

    window.call___back := Func("msg")
    window.addEventListener("mousemove",window.call___back)

    GuiControl,, GUI_InfoBox, % info
Return

msg(e:="") {
    Global document
    traytip, Mouse position on page, % "x: " e.pageX "`ny: " e.pageY
    ;MsgBox % document.elementFromPoint(e.pageX, e.pageY).innerHTML
}

IeGet(hWnd:=0) {
    WinGetTitle, title, % (hWnd ? "ahk_id " hWnd : "A")
    For window in ComObjCreate("Shell.Application").windows
        If (InStr(window.fullName, "iexplore.exe") && window.document.title . " - Internet Explorer" = title)
            Return window
    Return {}
}

ActiveIeMonitor(ByRef active) { ;we're using active.ie because it doesn't appear to be possible to pass a COM object directly using .Bind and SetTimer...
    active.ie := IeGet()
}

GuiClose() {
    ExitApp
}

0 个答案:

没有答案