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
Starred by 27 users
Forked by 9 users
Languages: JavaScript 76.6% | AutoHotkey 23.4%
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Communication between Autohotkey and Nodejs - AutoHotkey Community
October 11, 2019 - "\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 }
Discussions

jquery - How can I activate an AutoHotkey script using JavaScript? - Stack Overflow
I am developing a Chrome extension to help automate tasks. I have reached the point where I need my extension to trigger some AutoHotkey scripts. Is there any way I can trigger an AutoHotkey using More on stackoverflow.com
🌐 stackoverflow.com
node.js - Node - Trigger key/key combination on server - Stack Overflow
I was wondering if it's possible to make node emit keyboard events to the host's os. (something like autoHotKey) More on stackoverflow.com
🌐 stackoverflow.com
June 16, 2017
Need to run node.js through autohotkey. So far my way is too slow.

Add the directory to your computer's path, then a simple "Run, node main.js" should work.

More on reddit.com
🌐 r/AutoHotkey
6
0
September 4, 2019
Would one of you give me a quick crash course in how to interact with JavaScript using AHK to manipulate webpages?
Well, I don't know that I'm the best person to teach this topic, but I can certainly can point you to the references I used to learn. AHK Forums COM Object Reference - AutoHotkey Community ... Basic Webpage Controls With Javascript / Com - Tutorial - Tutorials ... Make Winhttp.waitforresponse() To Wait More Than 30 Seconds ... Urldownloadtofile - Look at the WinHttp Examples StackOverflow How to do logins using the WinHttpRequest COM - Stack Overflow autohotkey - WinHttpRequest timeouts - Stack Overflow Misc RESTful - Wikipedia The Component Object Model WinHttpRequest object HtmlFile Object - iHTMLDocument IE Com Object Practice Code Abbey - Interactive Problems Code Abbey - Social Web Scrapper I'll be happy to answer any questions you have. More on reddit.com
🌐 r/AutoHotkey
13
7
May 20, 2016
🌐
Reddit
reddit.com › r/autohotkey › running autohotkey from javascript
r/AutoHotkey on Reddit: Running AutoHotkey from JavaScript
April 12, 2020 -

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.

🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
AHK and Node JS, communication possible? - AutoHotkey Community
April 4, 2024 - 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
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.

🌐
Stack Overflow
stackoverflow.com › questions › 44579210 › node-trigger-key-key-combination-on-server
node.js - Node - Trigger key/key combination on server - Stack Overflow
June 16, 2017 - 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.
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Using Node.js for stdout, how to listen stdin in AHKv2? - AutoHotkey Community
March 22, 2023 - 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?
🌐
DebugTips
debugtips.com › executing javascript in chrome from autohotkey
Executing JavaScript in Chrome from AutoHotkey
November 25, 2025 - By using websocket in the node.js script to transfer JavaScript to web pages, you can essentially program and control the execution of AutoHotkey (and other local programs) and JavaScript in a complex way through node.js.
Find elsewhere
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
Javascript Wrapper (similar to Node.js) - AutoHotkey Community
September 2, 2014 - } } } Gui Show However, what I want is a more direct connection to AHK from Javascript code, so as not to rely on events (asynchronous), but on direct function calls (synchronous). That would allow the following code in Javascript: line 1: window.test = 1; line 2: API.callAHK(); // here AHK applies a change of value on "window.test" line 3: alert(window.test); // JS outputs a different value (not 1) Things I have tried:
🌐
GitHub
github.com › 1j01 › node-ahk
GitHub - 1j01/node-ahk: Desktop scripting with Node.js based on IronAHK ⌨🖱🔥
This project aims to use IronAHK in Node.js via Edge.js with the benefit of all the existing modules on npm.
Author: 1j01
🌐
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 4, 2019 - ... hit windows key, type "environment" and hit enter. click the button at the bottom that says Environment Variables. click one of the entries that says Path, either for the user (top) or the system (bottom). then just click New and navigate to the binary's directory. then when you type node, ...
🌐
GitHub
github.com › TheBrokenRail › AutoHotKey.js
GitHub - TheBrokenRail/AutoHotKey.js: Make AutoHotKey Scripts In JavaScript · GitHub
const autohotkey = require('autohotkey.js'); var script = new autohotkey.Script(); autohotkey.init('Name Of File', script); on('^t', function () { send('Hi'); });
Author: TheBrokenRail
🌐
GitHub
github.com › Lexikos › AutoHotkey-jk
GitHub - Lexikos/AutoHotkey-jk: AutoHotkey, running JavaScript. · GitHub
Most standard AutoHotkey functions are available, unless they are redundant (like the Math functions), AutoHotkey-specific (like HasMethod or VarSetStrCapacity) or disabled because they do not work (Exit) or are potentially unsafe due to the way jk works (StrPtr).
Author: Lexikos
🌐
Reddit
reddit.com › r/autohotkey › would one of you give me a quick crash course in how to interact with javascript using ahk to manipulate webpages?
r/AutoHotkey on Reddit: Would one of you give me a quick crash course in how to interact with JavaScript using AHK to manipulate webpages?
May 20, 2016 -

So I've avoided trying to interact with webpages via JavaScript since I started learning AHK, but curiosity has gotten the best of me.

You guys know I have the basics of AHK down and JavaScript was my very first "learn on my own" programming language. I'm so-so with it and haven't done a lot of it in YEARS.

Would any of you be able to give me a quick crash course on how to actually pass javascript commands to a browser?
I've seen people just do direct JavaScript injection via the address bar which I find to be very neat.

Are there other ways to do it?

I understand the DOM and how to find specific elements I want to change and what not. I can write basic webpages from scratch and put script tags in there. Just needing help bridging the two worlds :)

Any takers?
u/korbo-
u/radiantcabbage
u/testerteeto
u/bitx0r

1...2...3...GO!

Top answer
1 of 3
4
Well, I don't know that I'm the best person to teach this topic, but I can certainly can point you to the references I used to learn. AHK Forums COM Object Reference - AutoHotkey Community ... Basic Webpage Controls With Javascript / Com - Tutorial - Tutorials ... Make Winhttp.waitforresponse() To Wait More Than 30 Seconds ... Urldownloadtofile - Look at the WinHttp Examples StackOverflow How to do logins using the WinHttpRequest COM - Stack Overflow autohotkey - WinHttpRequest timeouts - Stack Overflow Misc RESTful - Wikipedia The Component Object Model WinHttpRequest object HtmlFile Object - iHTMLDocument IE Com Object Practice Code Abbey - Interactive Problems Code Abbey - Social Web Scrapper I'll be happy to answer any questions you have.
2 of 3
3
Well there are two ways of doing this. Since you have not provided any details I am going to assume that you will be using Firefox/Chrome and that you don't mind that you are basically not allowed do to anything while the script does its thing. Please also bear in my that this is my way of doing things, other people might do things differently. If you want any other type of getting information it is best done with direct webscraping (via Node.js, Python's BS4 ...) The problem for me was always that you cannot work with the DOM directly always as if the AHK script was a human passing in commands. So this is why all my commands are sequential. First way: Send {F6} Send javascript: //very important not to use sendinput as most browsers will just ignore/delete the input Send (function(){document.getElementsByClassName('title may-blank loggedin')[0].style.color="red"})(); //I wrapped the command in a IIFE (a function that is invoked immediately). Send {Enter} Second way: Use the built-in console to enter and run scripts. Send ^+j Send Clipboard //clipboard contains your script without the script tags Send {Enter} Of course if you navigate to different pages you have to redo the steps. You can run the first script and it will color the title of the thread red. Edited my answer because I realized the first one didn't work anymore so I had to check how to do it properly.
🌐
YouTube
youtube.com › nadjibsoft
Merge Javascript & AutoHotkey - YouTube
download this code: https://bit.ly/3OmgMXjNeed AHK Help? find me here: https://bit.ly/3Lifjj8----------------------------------------------------------------
Published: April 8, 2017
Views: 2K
🌐
GitHub
github.com › Lucasrsv1 › node-hotkeys
GitHub - Lucasrsv1/node-hotkeys: Handle hotkeys on NodeJS · GitHub
const hotkeys = require('node-hotkeys'); hotkeys.on({ hotkeys: 'ctrl + a', matchAllModifiers: true, callback: function (hotkey) { console.log("Activated:", hotkey); } });
Author: Lucasrsv1
🌐
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
🌐
npm
npm.io › home › node-ahk
node-ahk | npm.io
September 14, 2020 - const nodeahk = require('node-ahk'); ... gui.import("string"); // Imports this string as autohotkey. gui.write("event", "message"); // Send a buffer to autohotkey....
Published: Sep 11, 2020
Version: 1.0.7
Author: Niiko
🌐
npm
npmjs.com › search
keywords:ahk - npm search
Communication between AutoHotKey and NodeJS.