The HTTP route is probably the right way to go. You can easily set up a small Server using Node.js Node.js, and have it spawn your AHK script using one of the Child Process functions. I don't know how the Chrome Extension security model works, so you might have to mitigate cross-site scripting concerns. I think that's solvable, but haven't done so.

Answer from Wade Hatler on Stack Overflow
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Communication between Autohotkey and Nodejs - AutoHotkey Community
"\TestNode.js" if !FileExist(jsPath) FileAppend, % script, % jsPath Run, % "node """ jsPath """",, Hide, PID Process, Wait, % PID OnExit( Func("CloseNode").Bind(PID) ) Gui, Add, ActiveX, w200 h100 vWB, Shell.Explorer WB.Navigate("http://127.0.0.1:3000/") Loop { Sleep, 100 coll := WB.document.getElementsByTagName("button") } until coll.length coll[0].addEventListener("click", Func("OnClick").Bind(WB)) Gui, Show Return OnClick(WB) { MsgBox, % WB.document.documentElement.outerHTML } GuiClose() { ExitApp } CloseNode(PID) { Process, Close, % PID }
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
AHK and Node JS, communication possible? - AutoHotkey Community
I need your help with this, please! index.js · Code: Select all - Expand - Download - Line numbers - Word wrap - V2 · const spawn = require('child_process').spawn ahk = spawn("C:/Program Files/AutoHotkey/v2/AutoHotkey64.exe", ['ahk/stdin.ahk']); dataString = ''; ahk.stdout.on('data', function (data) { dataString += data.toString(); let toSend = ''; for (let i = 0; i < data.length; i++) { toSend += String.fromCharCode(data[i]); } console.log(toSend); }); ahk.stdout.on('end', function () { console.log('end'); }); ahk.stdin.write('some example' + '\r\n'); This is ahk/stdin.ahk
🌐
GitHub
github.com › RichardX366 › AHKNodeJS
GitHub - RichardX366/AHKNodeJS: Allows for communication between AutoHotKey.exe and NodeJS, giving access to AHK functions in NodeJS.
Allows for communication between AutoHotKey.exe and NodeJS, giving access to AHK functions in NodeJS. - RichardX366/AHKNodeJS
Starred by 26 users
Forked by 8 users
Languages   JavaScript 76.6% | AutoHotkey 23.4%
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Using Node.js for stdout, how to listen stdin in AHKv2? - AutoHotkey Community
import { ChildProcessWithoutNullStreams, spawn } from "child_process"; const child = spawn("C:/Program Files/AutoHotkey/v2/AutoHotkey64.exe", ["C:/scripts/AutoHotkey/v2/myScript.ahk"]); and then I think I can do something like this: child.stdin.write("Up" + "\n"); setTimeout(() => { child.stdin.write("Left" + "\n"); }, 1000); setTimeout(() => { child.stdin.write("Stop" + "\n"); }, 2000); setTimeout(() => { child.kill(); }, 3000); From AHK side, how would I listen for these things so that the script stays open and listens?
🌐
Reddit
reddit.com › r/autohotkey › running autohotkey from javascript
r/AutoHotkey on Reddit: Running AutoHotkey from JavaScript
December 3, 2019 -

Does anybody know a way in which I can write my code in JavaScript and still use basic AHK-Functionality like... hotkeys... Exo doesn't support it and ActiveScript seems to be the other way around.

Why? It seems so weird to me to set up a Hotkey and only then assigning a label to it without even referring to this specific Hotkey in any way:
Hotkey, IfWinActive, ahk_class Notepad

Hotkey, ^!e, MyLabel ; Creates a hotkey that works only in Notepad.

I can't really comprehend that. And writing everything in for example C# seems a bit too... dedicated?.

I have to apologize for my bad english, it's not my main language.

Top answer
1 of 2
2

The HTTP route is probably the right way to go. You can easily set up a small Server using Node.js Node.js, and have it spawn your AHK script using one of the Child Process functions. I don't know how the Chrome Extension security model works, so you might have to mitigate cross-site scripting concerns. I think that's solvable, but haven't done so.

2 of 2
1

Generally, two ways come to mind:

1. Emulating a HTTP Server using AHK

Using an own local web server (ideally a firsthand AHK implementation), you can directly communicate via AJAX calls. The server can then receive and delegate any kind of commands. For AHK, there exists Sparrow, but the project seems to be dead, and the source code links in the post are down; you'd have to get them from somewhere else (e.g. some svn repository). You could also implement a command line tool like KF Web Server and use it in conjunction with your script.

2. Defining your own protocol

Another solution would be to simply specify your own protocol and assign it to an executable, e.g. your script or some kind of dispatcher, that starts other applications depending on the parameters you pass it. This answer describes how to define your own protocol in windows. You can also check out the respective windows documentation.
If you're able to call custom protocols from within your browser with JavaScript strongly depends on your browser, and maybe its security settings. You'll need to check that out for your environment.

Security
No matter what solution you go with, giving a webpage the ability to run applications or even execute code opens up serious vulnerabilities. If an attacker finds out about your protocol, webserver, etc., they could easily inject their own stuff when you visit a website controlled by them. That's why you should at least implement two things:
a) Use some kind of authentication mechanism (e.g. HMAC). This makes exploitation at least a bit harder.
b) Never directly execute arguments as code. Always parse them and check their integrity.

🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Javascript Wrapper (similar to Node.js) - AutoHotkey Community
FixIE(true) Gui Add, ActiveX, w800 h600 vwb, Shell.Explorer wb.Navigate("about:blank") blob = ( <script> function manualTrigger(){ var evt = document.createEvent('MouseEvents'); evt.initEvent("click", true, true); document.getElementById('btn').dispatchEvent(evt); } </script> <input type='button' id='btn' onclick='alert("JS says Hi!")' value='BUTTON'> <input type='button' onclick='manualTrigger()' value='BUTTON'> ) wb.document.write(blob) btn := wb.document.All.btn ComObjConnect(btn, "btn_") btn_onclick() { MsgBox, AHK says Hi!
🌐
Reddit
reddit.com › r/autohotkey › need to run node.js through autohotkey. so far my way is too slow.
Need to run node.js through autohotkey. So far my way is too slow. : r/AutoHotkey
September 23, 2018 - You need to add the "C:\My Scripts\Convex Hull" folder to your system path. That way you can run "node main.js" from any location, then the first "Run, cmd /k C:\My Scripts\Convex Hull" command will no longer be necessary.
Find elsewhere
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
What's the best way to send commands in a NODE JS console window? - AutoHotkey Community
Hello. So I basically a NODE JS script and I want to pass variables to it WHILE it's running. Unfortunately, these variables exist in an Autohotkey script.
🌐
Reddit
reddit.com › r/node › any currently updated library that can do something like autohotkey in on javascript?
r/node on Reddit: any currently updated library that can do something like autohotkey in on javascript?
January 21, 2022 - Comment deleted by user · thanks. actually, those are the 2 i am looking at right now. Robots seems to be the most used one, but it stopped being updated 2 years ago. and nuts look solid, but almost no people seem to be using it
🌐
Stack Overflow
stackoverflow.com › questions › 44579210 › node-trigger-key-key-combination-on-server
node.js - Node - Trigger key/key combination on server - Stack Overflow
Though I have not used it myself. ... Sign up to request clarification or add additional context in comments. ... If you really like AutoHotkey, then you could simply trigger an AutoHotkey script from NodeJS.
🌐
npm
npmjs.com › package › node-ahk › v › 1.0.0
node-ahk - npm
const nodegui = require('node-ahk'); ... gui.import("string") ; // Imports this string as autohotkey. gui.write("event", "message"); // Send a buffer to autohotkey....
      » npm install node-ahk
    
Published   Sep 14, 2020
Version   1.0.0
Author   Niiko
🌐
YouTube
youtube.com › autohotkey gurus
🤯📈 Boost your automation game with JavaScript in AutoHotkey V2! 💪 - YouTube
in this video we demonstrate how you can have full access to JavaScript (technically Jscript) from within AutoHotkey. It's Amazing because you're actually p...
Published   July 6, 2022
Views   1K
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Exo: JavaScript unleashed! - AutoHotkey Community
provide useful typing (i.e. we shouldn't return String types everywhere only because it's easy) Usage Launch Exo with a ".js" file argument (either through drag-and-drop, or from the command-line):
🌐
npm
npmjs.com › search
keywords:ahk - npm search
Communication between AutoHotKey and NodeJS.
🌐
npms
npms.io › search
autohotkey.js
npms was built to empower the javascript community by providing a better and open sourced search for node modules.
🌐
Npm
npm.io › search › keyword:autohotkey
Autohotkey | npm.io
libnut is an N-API module for desktop automation with node · GUIAutomationmousekeyboardscreenshotimagedesktopscreenrecognitionautohotkey4.2.0 • Published 2 years ago · 🦅 cli syntax highlighting: any function - any object - 176 languages · syntaxhighlightclicolorconsoleterminallanguagehighlight.jschalkobject1.0.1 • Published 6 years ago