2
votes

Can someone explain how to use AutoHotKey to OUTPUT JavaScript when I type a piece of text? For example, I would like type...

iff

... and have AutoHotKey replace that text with...

if (err) { return callback(err); }

I've tried using Send, quotes, slashes... nothing works. I've also tried countless Google searches but everything finds people trying to CONTROL AutoHotKey with JavaScript instead of having it OUTPUT JavaScript.

2

2 Answers

2
votes

Adding :: at beginning and end of some text defines HotString that will do what you need. Also use SendRaw instead of Send because curly braces are special characters

::iff::
   SendRaw,if (err) { return callback(err); }
Return
0
votes

The ScriptControl Object allows AHk to execute javascript.

jSplode(str,del) {
    sc:=ComObjCreate("ScriptControl"),sc.Language:="JScript"
    js:="str='" str "';aR=str.split(""" del """);",sc.ExecuteStatement(js)
    Return sc.Eval("aR")
}

This is how your code would look:

js =
(
function ROloiw()
{
var map = ";
DL5=document.links;

for (lKi=0; lKi<DL5.length; lKi++)
{
map = map + DL5[lKi] + '|'
}

prompt('map', map );
}
ROloiw();
)

scObj.ExecuteStatement(js)