Code: Select all
/*
; AHK v2
global Console := new CConsole
Console.hotkey := "^+c" ; to show the console
Console.log "Hello", "world", "Mina", "konnichiha", "Bonjour tout le monde"
Console.show
Console.log "Point", {x:100,y:200}
;Hello world Mina konnichiha Bonjour tout le monde
;Point {
; x: 100
; y: 200
;}
*/
class CConsole {
ahkPID := ""
ahkHWND := ""
__New( title := "Console" ) {
HWND := WinExist( title " ahk_class Notepad" )
if ( HWND ) {
PID := WinGetPID( "ahk_id " HWND )
this.ahkPID := "ahk_pid " PID
this.ahkHWND := "ahk_id " HWND
this.clear
} else {
DetectHiddenWindows 1
Run "Notepad",,"Hide", PID
this.ahkPID := "ahk_pid " PID
HWND := WinWait(this.ahkPID)
if HWND=0
Return
this.ahkHWND := "ahk_id " HWND
WinMove(0, 0, A_ScreenWidth/4, A_ScreenHeight, this.ahkHWND)
WinSetTitle( title, this.ahkHWND )
WinShow( this.ahkHWND )
;WinActivate( this.ahkHWND )
}
Return this
}
hotkey{
set {
Hotkey value, ObjBindMethod(this, "show")
}
}
log( texts* ) {
if ( !WinExist( this.ahkHWND ) )
Return
last := texts.Length()
if last == 0
ControlEditPaste( "`r`n", "Edit1", this.ahkHWND )
for idx, txt in texts {
if (Type(txt)="Object") {
ControlEditPaste( "{`r`n", "Edit1", this.ahkHWND )
for key, value in txt {
ControlEditPaste( "`t" key ": " value "`r`n", "Edit1", this.ahkHWND )
}
ControlEditPaste( "}`r`n", "Edit1", this.ahkHWND )
} else {
rc := (idx=last? "`r`n" : " ")
ControlEditPaste( txt rc, "Edit1", this.ahkHWND ) ; ControlSendText ? ControlEditPaste
}
}
}
show() {
WinSetAlwaysOnTop( true, this.ahkHWND )
WinSetAlwaysOnTop( false, this.ahkHWND )
}
clear() {
ControlSetText( "", "Edit1", this.ahkHWND )
}
}