Last active
August 25, 2019 17:42
-
-
Save jmbeach/0bddd12bbebc19835536 to your computer and use it in GitHub Desktop.
AutoHotkey Console Log/WriteLine Equivalent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Inspired by thread:http://www.autohotkey.com/board/topic/103338-best-way-for-debug/?hl=%2Bconsole+%2Blog#entry638264 | |
;Based on script by user Hachi. | |
;Edit by Jared Beach. | |
; | |
; #include this script in a script you want to debug. | |
; "#Include, ./debug.ahk" | |
; | |
; Add debug messages by writing `debug("your message here")` | |
; | |
; See live debug messages by running: | |
; AutoHotkey myscript.ahk debug | Write-Host | |
; Exit the script by pressing Win + x. | |
;////////////////////////////////////////////////////////////////// | |
; Determine if this is a debug session | |
Gosub, SubCheckDebugArgs | |
; Works regardless if debug argument is passed in. | |
debug(string) { | |
string .= "`n" | |
FileAppend %string%,* ;* goes to stdout | |
} | |
; win + x ends script so you can see output in command-line | |
#x:: | |
{ | |
if (isDebug = true) { | |
Gosub, SubExit | |
} | |
Return | |
} | |
SubExit: | |
{ | |
ExitApp ;Terminate for debug | |
} | |
SubCheckDebugArgs: | |
{ | |
isDebug := false | |
i := 0 | |
Loop %0% { ; for all commandline arguments | |
param = %A_Index% | |
if (%param% = "debug") { | |
isDebug := true | |
} | |
} | |
Return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment