Skip to content

Instantly share code, notes, and snippets.

@alpgul
Created September 13, 2022 05:31
Show Gist options
  • Save alpgul/3f6ae4c6aeb99ebc408b08a4a05a3c4c to your computer and use it in GitHub Desktop.
Save alpgul/3f6ae4c6aeb99ebc408b08a4a05a3c4c to your computer and use it in GitHub Desktop.
AHK Debug Message
DebugMessage(str)
{
global h_stdout
DebugConsoleInitialize() ; start console window if not yet started
str .= "`n" ; add line feed
DllCall("WriteFile", "uint", h_Stdout, "uint", &str, "uint", StrLen(str), "uint*", BytesWritten, "uint", NULL) ; write into the console
WinSet, Bottom,, ahk_id %h_stout% ; keep console on bottom
}
DebugConsoleInitialize()
{
global h_Stdout ; Handle for console
static is_open = 0 ; toogle whether opened before
if (is_open = 1) ; yes, so don't open again
return
is_open := 1
; two calls to open, no error check (it's debug, so you know what you are doing)
DllCall("AttachConsole", int, -1, int)
DllCall("AllocConsole", int)
dllcall("SetConsoleTitle", "str","Paddy Debug Console") ; Set the name. Example. Probably could use a_scriptname here
h_Stdout := DllCall("GetStdHandle", "int", -11) ; get the handle
WinSet, Bottom,, ahk_id %h_stout% ; make sure it's on the bottom
WinActivate,Lightroom ; Application specific; I need to make sure this application is running in the foreground. YMMV
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment