A simple "Console.log" for debugging or developping time.

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

A simple "Console.log" for debugging or developping time.

21 May 2019, 04:38

This is usefull for me. May be for you too ?

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 )
	}

}

shebang(0.1;"test/doc.php");
Last edited by FredOoo on 09 Jun 2019, 22:48, edited 2 times in total.
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: A simple "Console.log" for debugging or developping time.

21 May 2019, 23:37

For v 1.1?
User avatar
DataLife
Posts: 445
Joined: 29 Sep 2013, 19:52

Re: A simple "Console.log" for debugging or developping time.

23 May 2019, 11:51

Is there anyone willing to convert this to v 1.1?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A simple "Console.log" for debugging or developping time.

23 May 2019, 12:33

I used a partial AHK v2 -> AHK v1 converter, which I will release ..., and I double-checked other lines. It might work as is, possibly you need to check the Hotkey command, and/or other lines. Cheers.

Code: Select all

/*
	; AHK v1.1
	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 ) {
			WinGet, PID, PID, % "ahk_id " HWND
			this.ahkPID  := "ahk_pid " PID
			this.ahkHWND := "ahk_id  " HWND
			this.clear()
		} else {
			DetectHiddenWindows, On
			Run, Notepad,, Hide, PID
			this.ahkPID := "ahk_pid " PID
			WinWait, % this.ahkPID
			HWND := WinExist()
			if HWND=0
				return
			this.ahkHWND := "ahk_id  " HWND
			WinMove, % this.ahkHWND,, 0, 0, % A_ScreenWidth/4, % A_ScreenHeight
			WinSetTitle, % this.ahkHWND,, % title
			WinShow, % this.ahkHWND
			;WinActivate, % this.ahkHWND
		}
		return this
    }

	hotkey{
		set {
			show_bind := ObjBindMethod(this, "show")
			Hotkey, % value, % show_bind
		}
	}


	log( texts* ) {
		if ( !WinExist( this.ahkHWND ) )
			return
		last := texts.Length()
		if last == 0
			Control, EditPaste, % "`r`n", Edit1, % this.ahkHWND
		for idx, txt in texts {
			;if (Type(txt)="Object") {
			if (IsObject(txt)) {
				Control, EditPaste, % "{`r`n", Edit1, % this.ahkHWND
				for key, value in txt {
					Control, EditPaste, % "`t" key ": " value "`r`n", Edit1, % this.ahkHWND
				}
				Control, EditPaste, % "}`r`n", Edit1, % this.ahkHWND
			} else {
				rc := (idx=last? "`r`n" : " ")
				Control, EditPaste, % txt rc, Edit1, % this.ahkHWND  ; ControlSendText ? ControlEditPaste
			}
		}
	}

	show() {
		WinSet, AlwaysOnTop, % true, % this.ahkHWND
		WinSet, AlwaysOnTop, % false, % this.ahkHWND
	}

	clear() {
		ControlSetText, Edit1,, % this.ahkHWND
	}

}
Last edited by jeeswg on 24 May 2019, 08:36, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: A simple "Console.log" for debugging or developping time.

24 May 2019, 08:00

 »
 » I start learning AHK with v2 because v1 syntax is horrible, but I did it.
 »

Code: Select all

/*
	; AHK v1.1
	global Console := new CConsole
	Console.hotkey := "^+c"  ; to show the Console
	Console.log("Hello", "world", "Mina", "konnichiha", "Bonjour tout le monde")
	Console.show()  ; must use parentheses
	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 ) {
			WinGet, PID, PID, % "ahk_id " HWND
			this.ahkPID  := "ahk_pid " PID
			this.ahkHWND := "ahk_id " HWND
			this.clear()
		} else {
			DetectHiddenWindows, On
			Run, Notepad,, Hide, PID
			this.ahkPID := "ahk_pid " PID
			WinWait, % this.ahkPID
			HWND := WinExist( this.ahkPID )
			if HWND=0
				return
			this.ahkHWND := "ahk_id " HWND
			WinMove, % this.ahkHWND,, 0, 0, % A_ScreenWidth/4, % A_ScreenHeight
			WinSetTitle, % this.ahkHWND,, %title%
			;WinActivate, % this.ahkHWND
			WinShow, % this.ahkHWND
		}
    }

	hotkey{
		set {
			show_bind := ObjBindMethod( this, "show" )
			Hotkey, % value, % show_bind
		}
	}

	log( texts* ) {
		if ( !WinExist( this.ahkHWND ) )
			return
		last := texts.Length()
		if last == 0
			Control, EditPaste, % "`r`n", Edit1, % this.ahkHWND
		for index, txt in texts {
			if (IsObject(txt)) {
				Control, EditPaste, % "{`r`n", Edit1, % this.ahkHWND
				for key, value in txt {
					Control, EditPaste, % "`t" key ": " value "`r`n", Edit1, % this.ahkHWND
				}
				Control, EditPaste, % "}`r`n", Edit1, % this.ahkHWND
			} else {
				sep := (index=last? "`r`n" : " ")
				Control, EditPaste, % txt sep, Edit1, % this.ahkHWND  ; ControlSendText ? ControlEditPaste
			}
		}
	}

	show() {
		WinSet, AlwaysOnTop, % true, % this.ahkHWND
		WinSet, AlwaysOnTop, % false, % this.ahkHWND
	}

	clear() {
		ControlSetText, Edit1,, % this.ahkHWND
	}

}
Last edited by FredOoo on 24 May 2019, 14:04, edited 1 time in total.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A simple "Console.log" for debugging or developping time.

24 May 2019, 09:40

@FredOoo: Your conversion looks right apart from:

Code: Select all

HWND := WinExist( %title% " ahk_class Notepad" ) ;before
HWND := WinExist( title " ahk_class Notepad" ) ;after
Also: your conversion appears to lack return this, although maybe it doesn't need it, I haven't tested.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: A simple "Console.log" for debugging or developping time.

24 May 2019, 09:54

FredOoo wrote:
24 May 2019, 08:00
 »
 » I start learning AHK with v2 because v1 syntax is horrible, but I did it.
 »

Code: Select all

/*
	; AHK v1.1
	global Console := new CConsole
	Console.hotkey := "^+c"  ; to show the Console
	Console.log("Hello", "world", "Mina", "konnichiha", "Bonjour tout le monde")
	Console.show()  ; must use parentheses
	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 ) {
			WinGet, PID, PID, % "ahk_id " HWND
			this.ahkPID  := "ahk_pid " PID
			this.ahkHWND := "ahk_id  " HWND
			this.clear()
		} else {
			DetectHiddenWindows, On
			Run, Notepad,, Hide, PID
			this.ahkPID := "ahk_pid " PID
			WinWait, % this.ahkPID
			HWND := WinExist( this.ahkPID )
			if HWND=0
				return
			this.ahkHWND := "ahk_id  " HWND
			WinMove, % this.ahkHWND,, 0, 0, % A_ScreenWidth/4, % A_ScreenHeight
			WinSetTitle, % this.ahkHWND,, %title%
			;WinActivate, % this.ahkHWND
			WinShow, % this.ahkHWND
		}
    }

	hotkey{
		set {
			show_bind := ObjBindMethod( this, "show" )
			Hotkey, % value, % show_bind
		}
	}

	log( texts* ) {
		if ( !WinExist( this.ahkHWND ) )
			return
		last := texts.Length()
		if last == 0
			Control, EditPaste, % "`r`n", Edit1, % this.ahkHWND
		for index, txt in texts {
			if (IsObject(txt)) {
				Control, EditPaste, % "{`r`n", Edit1, % this.ahkHWND
				for key, value in txt {
					Control, EditPaste, % "`t" key ": " value "`r`n", Edit1, % this.ahkHWND
				}
				Control, EditPaste, % "}`r`n", Edit1, % this.ahkHWND
			} else {
				sep := (index=last? "`r`n" : " ")
				Control, EditPaste, % txt sep, Edit1, % this.ahkHWND  ; ControlSendText ? ControlEditPaste
			}
		}
	}

	show() {
		WinSet, AlwaysOnTop, % true, % this.ahkHWND
		WinSet, AlwaysOnTop, % false, % this.ahkHWND
	}

	clear() {
		ControlSetText, Edit1,, % this.ahkHWND
	}

}
Thank you very much. This is really a big help since i write a script that become larger + buggy, and i'm i bit tired to debugging it with MsgBox.
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: A simple "Console.log" for debugging or developping time.

24 May 2019, 10:04

@jeeswg
Did you really able to convert all [most] of v2 to v1? Can wait for the release. :superhappy:
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: A simple "Console.log" for debugging or developping time.

24 May 2019, 10:09

To be honest, I don't feel very confident with the %var% or % expression syntax.
I got « title » as window's title so I tryed and tryed many syntaxes.
HWND := WinExist( title " ahk_class Notepad" ) ;; You're right

Also, I saw this in the doc:
return this ; This line can be omitted when using the 'new' operator.
https://www.autohotkey.com/docs/Objects.htm#Custom_Classes
(and the same with AHK v2)

By the way, thank's jeeswg: I wouldn't have done this if you have not done the first v1 conversion.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Rohwedder and 81 guests