AHK and Node JS, communication possible?
Posted: 04 Apr 2024, 06:41
I want to run my index.js file and have it open an .ahk file. With different hotkeys in the .ahk file, I should be able to call my running Node.js script (while it's running). For example, if I press the 'H' key, it should console.log("Pressed h from ahk, showing on JavaScript"). I need your help with this, please!
index.js
This is ahk/stdin.ahk
So when i open stdin.ahk from AHK works well! But when I "node index.js" the console appears but i cant write, any solution? Or anyway to get what i want? handle hotkeys from ahk and do something on nodejs (javascript). Example: when press "h" console.log("hoello world from ahk to node js")
index.js
Code: Select all
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');
Code: Select all
DllCall("AllocConsole")
stdin := FileOpen("*", "r `n")
stdout := FileOpen("*", "w `n")
init()
Return
~esc::{
ExitApp
}
init(){
While(True){
stdout.Write("Enter your query.`n\> ")
stdout.Read(0)
query := RTrim(stdin.ReadLine(), "`n")
stdout.WriteLine("Your query was '" query "'. Have a nice day.")
stdout.Read(0)
}
}