AHK and Node JS, communication possible?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

AHK and Node JS, communication possible?

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

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');
This is ahk/stdin.ahk

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) 
    }
}
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")
My WEB some useful stuff

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: gekunfei, philbxl and 47 guests