Debugger clear screen with Autohotkey

By | 2022/04/20

Using Sysinternal Debugview and Autohotkey.
The following code example sends a Ctrl + x to the Debugview to clear the screen at script-startup.

Also shows how to send text to the SciTE4AutoHotkey console-window.

; debugTest.ahk
#Warn, All, StdOut ; SciTE4AutoHotkey
#SingleInstance force
  
gui, new
gui, font, s12 Calibra
gui, add, text, Vtext1 w400 xm ym
gui, show, w400 h50 center,Test console-output to SciTE4AutoHotkey
run()
return

run(){
  dbgClear()
  msg := "Script (" . getTimeStamp() . "): Start debugTest" . "`n"
  consoleWrite(msg)
  dbgWrite(msg)

  loop,5 {
      msg := "Script (" . getTimeStamp() . "): " . A_Index . "`n"
      consoleWrite(msg)
      dbgWrite(msg)
      
      GuiControl,,text1,%msg%
      sleep,400
  }

  msg := "debugTest finished!" . "`n"
  GuiControl,,text1,%msg%
  consoleWrite(msg)
  dbgWrite(msg)
  sleep,2000
  
  msg := "By by ...!" . "`n"
  GuiControl,,text1,%msg%
  consoleWrite(msg)
  dbgWrite(msg)
  sleep,1000
  exitApp
  
}
 
;--------------------------------- guiClose ---------------------------------
guiClose(){
  exitApp
}
;------------------------------- getTimeStamp -------------------------------
getTimeStamp(){
    FormatTime, TimeString, %A_Now%, yyyy MM dd HH:mm:ss tt
    return TimeString
}
;--------------------------------- dbgClear ---------------------------------
dbgClear(){
  ; call after gui exists!
  currentWin := WinExist("A")
  if (WinExist("ahk_class dbgviewClass")){
      WinActivate,ahk_class dbgviewClass
      WinWaitActive,ahk_class dbgviewClass,,10
      ; debugger clear-screen
      SendInput,{Control Down}x{Control Up}
      WinActivate,ahk_id %currentWin%,,10
      WinWaitActive,ahk_id %currentWin%,,10
  }
   return
} 
;------------------------------- consoleWrite -------------------------------
consoleWrite(t := ""){
  ;console output
  FileAppend %t%, *
  return
}
;--------------------------------- dbgWrite ---------------------------------
dbgWrite(t := ""){
  ;debug output
  OutputDebug, %t%
  return
}