Page 1 of 1

[Autohotkey-jk] winGetControls returns an array that can't be iterated over?

Posted: 13 Apr 2022, 01:13
by func
I have a really strange result from using winGetControls in autohotkey-jk, on various windows, so for example in notepad, it will find 2 controls.

Code: Select all

Controls = winGetControls("Notepad")
msgBox(Controls.length) // outputs: 2
msgBox(JSON.stringify(Controls)) // outputs: {}
So it seems to be working, but every way to iterate an array, object, or other iterable, or print a variable in javascript is not working. Everything is blank, except JSON.stringify(Controls), which outputs "{}" an empty object. This is the same for windows that show 150 controls in Controls.length

I don't understand what is happening, is there some magic way to iterate the result of winGetControls in autohotkey-jk?

Re: [Autohotkey-jk] winGetControls returns an array that can't be iterated over?

Posted: 13 Apr 2022, 01:26
by func
I found out Controls.pop() works, so that's encouraging

Re: [Autohotkey-jk] winGetControls returns an array that can't be iterated over?  Topic is solved

Posted: 14 Apr 2022, 18:49
by lexikos
It returns an AutoHotkey Array, not a JavaScript Array. As far as I can recall, there isn't any way to call a property getter/setter with parameters in JavaScript, aside from explicitly retrieving it with GetOwnPropDesc.

To fix it, you can just add the following to funcs.ahk (and recompile jk if you're using it that way).

Code: Select all

ArrayToJs(a) => js.Array(a*)
WinGetControls.returns := ArrayToJs
WinGetControlsHwnd.returns := ArrayToJs
ControlGetItems.returns := ArrayToJs
For each AutoHotkey function exposed to JavaScript, jk uses function.returns (or function.output if it has output parameters), if present, to translate the return value to something appropriate for JavaScript.