Reputation: 14054
I'm constantly trying to run quick tests in AHK. It's a pain to have to think of a new hot key, write all the environmental variables, save, build, etc. I'd like to be able to type out a short test, press enter, and get some feedback from AHK.
For instance: I'd type Run, Notepad
in an AHK console, press enter, Notepad opens, and some feedback is displayed in the console. Then I can go back, play around with options, press enter, etc. So it would look like this:
> Run, Notepad
Running Notepad.exe
Activating Window Untitled - Notepad, ahk_class Notepad, ahk_id ...
Window Active
> Run, NotARealThing
Error: Could not find 'NotARealThing'
>
GirlGamer
's "Script for quick run of scripts" However...
Run, TempScript.ahk
because the system could not find it, even though FileAppend
is supposed to create a new file if it doesn't exist.^!W
) is pretty close to what I'm looking for. But, I'd like to press Enter and have it run, and Shift+Enter goes to the next line... AutoHotkey Console Log/WriteLine Equivalent.
Initially I thought this was the solution, but it says "If you run this from console..." What console?
Furthermore, it claims you can do something like > AutoHotKey test.ahk
but I see a few problems with this:
AutoHotKey
as a command. I'm sure this means I simply need to add the path to AutoHotKey.exe to my PATH variable.SCiTE4AHK but I don't see anything that says "console" there...
Hachi
's answer to "Best way for debug ?"
"so run from console
myscript.ahk >log.txt
ormyscript.ahk |more
"
Also a bunch of Google search results. But it seems like everything refers to the console, never how to actually get to the console. What am I missing?
Upvotes: 5
Views: 7380
Reputation: 699
My first attempt was create an IE window, and push message into the body of HTML. It works not so well, the scrolling is impossible, Ive tried with down to up concatenate.. and there is window activating problem, and the timing.. so it is not so good.
There is a second workaround, because AHK has not console, the click on its icon on tray and check the flow, it isnt what you has wanted. The idea is that: sending messages to console assincrously wia webservice.
There is the code of webservice, nodejsconsole.js, it needs nodeJS and several npm package.
var express = require('express');
var app = express();
var colors = require('colors');
const strftime = require('strftime');
var port = 3003;
var ip = '127.0.0.1';
app.listen(port, ip, function() {
});
app.post('*', function( req, res ){
var bodyStr = '';
req.on("data",function(chunk){
bodyStr += chunk.toString();
});
req.on("end",function(){
msg="";
switch( bodyStr.substr(0,1) )
{
case String.fromCharCode(7) :
tmp=bodyStr.split(String.fromCharCode(7));
for(i=1;i<tmp.length;i=i+2){
msg=msg+" "+tmp[i][tmp[i+1]];
}
msg=msg.substr(1);
break;
case '[' :
case '{' :
msg=JSON.parse(bodyStr);
break;
default:
msg=bodyStr;
break;
}
console.log(strftime('%T.%L').cyan,msg);
res.json({"OK":200});
});
});
This gets the string and show it in the console window. It shows well the stringified valid JSON, and string, and you can colorize your message with chr(7) started and separated string.
The ahk function jsconsole.ahk is search for a console window, if it not exists, run it, if exists, show the message. Ive just put it into my ahk lib.
jsconsole( msg )
{
try {
global req
if(!req)
{
req:= ComObjCreate("WinHttp.Winhttprequest.5.1")
req.open("POST","http://localhost:3003/")
req.setRequestHeader("Accept", "application/json")
}
req.send( msg )
; req.close()
} catch e {
if( instr( e.message, "0x80072EFD" )) ;maybe your errorcode is different, handle it well here
{
Run, % "node """ A_scriptdir "\nodejsconsole.js""", % A_scriptdir
WinWaitActive, c:\progra~1\nodejs\node.exe
WinActivate, c:\progra~1\nodejs\node.exe
WinMove, c:\progra~1\nodejs\node.exe, , A_ScreenWidth, 0, A_ScreenWidth/3, A_ScreenHeight-80 ; I have 2 screens, this positions it to the second one left side
req.send( msg )
} else
msgbox % e.message
}
}
Test them with run this example.ahk:
jsconsole( A_now " indult a log" )
jsconsole( "{""key"":{""kiy"":{""kuy"":3}}}" )
jsconsole( "[""hátezegykey"",2,4,3.12]" )
jsconsole( chr(7) "chartestíéáőúüóö" chr(7) "cyan" chr(7) "10" chr(7) "magenta" )
Upvotes: 0
Reputation: 14054
For CodeQuickTester, copy the code (found here), put it in a new .ahk
file, and build it to start the AHK console. It doesn't have the Enter functionality you wanted, but you can easily set that up if you want.
You can also setup a script to launch the console, like this:
; win+c launches the AutoHotKey Console
#c::
Run, AHK_Console.ahk, C:\path\to\ahk\scripts
Return
Upvotes: 0
Reputation: 2672
Ahk doesn't work like that, out of the box. The Console they are referring to is the Windows Command console. Now with that said:
Check this out: https://github.com/G33kDude/Console And this: https://autohotkey.com/boards/viewtopic.php?f=6&t=6113
Upvotes: 7