Why can AHK inject functions into IE such that they can be called from JS so easily?

Get help with using AutoHotkey and its commands and hotkeys
Posts: 212
Joined: 01 Mar 2016, 14:52

Why can AHK inject functions into IE such that they can be called from JS so easily?

23 Jun 2018, 08:51

Hi all,

So last week I posted this stackoverflow question. For those who don't already know you can inject AHK functions into Internet Explorer such that they can be called from JavaScript. An Example:

Code: Select all


html =
      document.setVar = function`(name,val`){

ie := ComObjCreate("InternetExplorer.Application")
sleep, 2000

msgbox, %html%
ie.visible := true

  msgbox, "hello"
By registering someFunc we can now call it directly from JavaScript using document.someFunc()

My question is, why does this work so well?! What are the conditions that ie.document.setVar("someFunc",Func("someFunc")) actually injects the function into JS, like on a low level I mean. Does someFunc need to be wrapped in some IDispatch? Or does it have to have some other COM properties?

The reason I am asking is because I can't for the life of me figure out how I can do the same in Ruby... So far everything I have tried seemed like it could work, but nothing really did... Any ideas?

I am using Ruby on Windows (Cygwin), FYI.


I've also seen that Function objects are a little different in AHK. Is this part of the reason? Do passed functions have to be actual objects which have a Call() and a __Call() method?

Code: Select all

class YourClassName {
    Call(a, b) {  ; Declare parameters as needed, or an array*.
    __Call(method, args*) {
        if (method = "")  ; For %fn%() or fn.()
            return this.Call(args*)
        if (IsObject(method))  ; If this function object is being used as a method.
            return this.Call(method, args*)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Flipeador, HotKeyIt, MannyKSoSo, sinkfaze and 54 guests