Js and ahk

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hieveryone
Posts: 43
Joined: 28 Nov 2022, 01:31

Js and ahk

Post by hieveryone » 28 Nov 2022, 21:59

Sorry for before I ment js not is but auto correct
How to use js/could you use js?

Thanks

teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: Js and ahk

Post by teadrinker » 29 Nov 2022, 04:36

What are you going to do with it?

bestuser
Posts: 15
Joined: 15 Sep 2022, 07:11

Re: Js and ahk

Post by bestuser » 29 Nov 2022, 06:08

Hey,

You can include functionalities from other languages using DllCall()

hieveryone
Posts: 43
Joined: 28 Nov 2022, 01:31

Re: Js and ahk

Post by hieveryone » 29 Nov 2022, 23:47

teadrinker wrote:
29 Nov 2022, 04:36
What are you going to do with it?
Not anything at the moment just figured it will be useful for more complex stuff

Leafk
Posts: 30
Joined: 11 Nov 2022, 22:09

Re: Js and ahk

Post by Leafk » 30 Nov 2022, 08:12

Js as in Javascript?
You can use the MS version (JScript) with COM

Code: Select all

JS_Eval(str) {
    ;htmlfile := ComObject("htmlfile") ;v2 sintax
    htmlfile := ComObjCreate("htmlfile") ;v1 sintax
    htmlfile.write("<meta http-equiv='X-UA-Compatible' content='IE=edge'>")
    return htmlfile.parentWindow.eval(str)
}
JS_Eval("alert('testing');alert('another test!')")
The core of the code is:
On line 2 it creates one internet explorer object (think like it opens IE but without it's gui)
On line 3 it includes the header meta equivalent to accept newer Jscript commands (by default it is IE6 if I'm not wrong)
On line 4 it runs the ie function eval ( htmlfile.parentWindow.eval() ). You can use directly functions from JS using like that.

Optionally you can go directly with the COM object only.

Code: Select all

htmlfile := ComObjCreate("htmlfile") ;v1 sintax
;htmlfile := ComObject('htmlfile') ;v2 sintax
htmlfile.write("<meta http-equiv='X-UA-Compatible' content='IE=edge'>")
JS := htmlfile.parentWindow
JS.eval("var testVar = 'something' ")
JS.alert("testing")
JS.alert("another test! " . JS.testVar )
msgbox % JS.testVar
The code is not javascript and has it's own quirks when using.
You need to be mindfull when doing hybrid because it's easy to forget if your sintax is currently on AHK layer or in JS layer.
Last edited by Leafk on 30 Nov 2022, 10:02, edited 1 time in total.

teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: Js and ahk

Post by teadrinker » 30 Nov 2022, 09:09

Leafk wrote:

Code: Select all

htmlfile := ComObject('htmlfile')
Here v1 thread! :)
Leafk wrote: think like it opens IE but without it's gui
Nope.

Leafk
Posts: 30
Joined: 11 Nov 2022, 22:09

Re: Js and ahk

Post by Leafk » 30 Nov 2022, 09:58

Whoops my bad. I'll edit to make it v1 compliant.

Post Reply

Return to “Ask for Help (v1)”