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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
func
Posts: 47
Joined: 20 May 2016, 20:52

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

13 Apr 2022, 01:13

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?
func
Posts: 47
Joined: 20 May 2016, 20:52

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

13 Apr 2022, 01:26

I found out Controls.pop() works, so that's encouraging
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

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

14 Apr 2022, 18:49

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.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Marium0505, mikeyww and 22 guests