HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

English support forum

Moderators: Stefan2, white, sheep, Hacker

Post Reply
User avatar
artt
Junior Member
Junior Member
Posts: 44
Joined: 2009-05-03, 07:03 UTC

HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *artt » 2019-03-12, 22:29 UTC

Hi,
nsp wrote:
2012-10-19, 07:34 UTC
The complete syntax is in fact :
<Left>\r<Right>\0
<Source>\r<Target>\0S
<Left>\r<Right>\0T open in new Tab
ghisler(Author) wrote:
2006-11-19, 23:42 UTC
You can set only one path of the two by leaving it empty (the 0x13 ENTER char must be present, though).

There are also two parameters after the final 0x00 character (second path end):
T causes the path to be opened in a new tab
S causes the path to be seen as source and target instead of left+right
ghisler(Author) wrote:
2006-11-27, 21:17 UTC
After the final #0 character of the paths, add an 'S' to handle paths as source/target, and/or a 'T' to show the paths in new tabs.
Using next AutoHotkey code i can open Dirs "LR" and/or "ST" in place of current Dirs.
But how can i open them in a NEW TAB ?
(All my tests to add final #0 character and 'T' fail)

Can anyone help?
Thanks

Code: Select all

F5::	; Press F5 to run
WinActivate, ahk_class TTOTAL_CMD
MsgBox,4096,1,1
TC_WMCopyData( "C:\tc"     "`r"     "D:\data", "LR" )
MsgBox,4096,1,2
TC_WMCopyData( "D:\data"     "`r"     "C:\tc", "LR" )
Return


TC_WMCopyData( cmd, Type="" ) {
	Critical
	
	; --- ANY OF NEXT FAIL TO OPEN DIRS IN NEW TAB:
	;cmd := cmd chr(3) Asc("\") Asc("T")
	;cmd := cmd chr(3) Asc("T")
	;cmd := cmd chr(0) Asc("\") Asc("T")
	;cmd := cmd chr(0) Asc("T")
	;cmd := cmd chr(3) "\T"
	;cmd := cmd chr(3) "T"
	;cmd := cmd chr(0) "\T"
	;cmd := cmd chr(0) "T"
	
	
	VarSetCapacity( CopyDataStruct, A_PtrSize * 3 )
	(A_IsUnicode ? VarSetCapacity(cmdA,StrPut(cmd,"cp0"),0) StrPut(cmd,&cmdA,"cp0") :"")
	NumPut( Asc("C") + 256 * Asc("D"), CopyDataStruct,0 )
	NumPut( StrLen(cmd) + 5 * (A_IsUnicode ? 2 : 1), CopyDataStruct, A_PtrSize )
	NumPut((A_IsUnicode ? &cmdA : &cmd), CopyDataStruct, A_PtrSize * 2)
	NumPut( Asc(SubStr(Type,1,1)) Asc(SubStr(Type,2,1)),(A_IsUnicode ? cmdA : cmd),StrLen(cmd)+1,"Char")
	SendMessage, 0x4A,, &CopyDataStruct,, ahk_class TTOTAL_CMD
}

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37264
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *ghisler(Author) » 2019-03-13, 08:16 UTC

I have checked what Total Commander receives: It receives the first path, then character #13 (not 0x13, 0x0D), then the second path, then #0, then #2 (0x02) and then again 0x00.
So apparently this is wrong:

Code: Select all

NumPut( Asc(SubStr(Type,1,1)) Asc(SubStr(Type,2,1)),(A_IsUnicode ? cmdA : cmd),StrLen(cmd)+1,"Char")
The following works for me:

Code: Select all

	NumPut( Asc(SubStr(Type,1,1)) ,(A_IsUnicode ? cmdA : cmd),StrLen(cmd)+1,"Char")
	NumPut( Asc(SubStr(Type,2,1)) ,(A_IsUnicode ? cmdA : cmd),StrLen(cmd)+2,"Char")
However, there are a few more flaws:
1. Sending "LR" makes no sense. The first tells TC to activate the left window, and the second the right window. The meaning of the placeholders is:
S: Interpret the paths as source/target instead of left/right
T: Open path(s) in new tabs
B: Open tabs in background (do not activate them)
L: Activate the left panel
R: Activate the right panel
A: Do not open archives as directories. Instead, open parent directory and place cursor on it.
TC accepts more then 2 parameters here, so sending e.g. STBL is legitimate.
2. Unicode can be handled by sending either UTF-8 or UTF-16 text WITH byte order marker (BOM). Both paths MUST be preceded by the BOM. Only Intel word order is supported for UTF-16 (bom=FF FE).
Author of Total Commander
http://www.ghisler.com

User avatar
artt
Junior Member
Junior Member
Posts: 44
Joined: 2009-05-03, 07:03 UTC

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *artt » 2019-03-14, 13:59 UTC

@Ghisler
Thank you for your reply - i had misunderstand the usage of placeholders and now all are clear to me!

ghisler(Author) wrote:
2019-03-13, 08:16 UTC
...It receives the first path, then character #13 (not 0x13, 0x0D)...
Is this wrong? For AutoHotkey, the escaped r [`r] i am using to separate 1st and 2nd path is the CR "carriage return", ASCII DEC=13, ASCII HEX=0x0D.
Additionally, by using `r TC handle the paths correctly.

ghisler(Author) wrote:
2019-03-13, 08:16 UTC
2. Unicode can be handled by sending either UTF-8 or UTF-16 text WITH byte order marker (BOM).
I didn't try to send unicode before. Until now I convert all the [LeftPath `r RightPath] string to the system's default ANSI code page (CP0).
This is working for Eng and Greek language paths.


In the following script:
-- any number of placeholders (i call them Flags) must send correctly to TC now.
-- there are 5 tests (Modes) for testing to send the paths as UTF-8 and UTF-16. The last mode is sending paths in system's default ANSI code page.
-- there are 4 paths for test - 2 with English characters only and 2 with Greek characters.

Modes:
Mode=1 ["UTF-8 BOM" Path1 "`r" "UTF-8 BOM" Path2] converted to UTF-8
Mode=2 ["UTF-8 BOM" Path1 "`r" "UTF-8 BOM" Path2] converted to UTF-8 (2nd way)
Mode=3 ["UTF-16 BOM" Path1 "`r" "UTF-16 BOM" Path2] converted to UTF-8
Mode=4 ["UTF-16 BOM" Path1 "`r" "UTF-16 BOM" Path2] converted to UTF-16
Mode=5 [Path1 "`r" Path2] converted to the system's default ANSI code page (CP0).

Results:
Mode=1: EN_Paths=OK, GR_Paths=FAIL
Mode=2: EN_Paths=FAIL, GR_Paths=FAIL
Mode=3: EN_Paths=OK, GR_Paths=OK, Flags=OK (For some reason, UTF-8 but with UTF-16 BOM, working OK !!!)
Mode=4: EN_Paths=OK, GR_Paths=OK, Flags=FAIL
Mode=5: EN_Paths=OK, GR_Paths=OK, Flags=OK




Christian, can you please test the script (and with other than Greek characters in paths), mainly Modes 3 and 5 that are working to me?
I will clean up the script to use only the Mode you will suggest.

Thank you very much
Best Regards

Code: Select all

#SingleINSTANCE, Force

P1_EN := "D:\__APPS__\"
P1_GR := "D:\__ΕΓΓΡΑΦΑ___\ΑΙΤΗΣΗ-ΔΗΛΩΣΗ-ΕΞΟΥΣΙΟΔΟΤΗΣΗ\"
P2_EN := "C:\FirefoxDownloads\!TC\"
P2_GR := "D:\__ΘΕΜΑΤΑ____\ΔΙΑΣΚΕΔΑΣΗ\ΑΝΕΚΔΟΤΑ\"
Return

F5::
WinActivate, ahk_class TTOTAL_CMD
LOOP, 5
	{
	IF A_INDEX IN 1,2,4	; ByPass/Dissable FAIL Modes
		Continue
	TC_WMCopyData( P1_EN, P1_GR, "LT", A_INDEX )
	MsgBox,4096,Mode = %A_INDEX%,*[%P1_EN%]`n`n[%P1_GR%]
	TC_WMCopyData( P2_GR, P2_EN, "RT", A_INDEX )
	MsgBox,4096, Mode = %A_INDEX%,[%P2_GR%]`n`n*[%P2_EN%]
	}
Return

/*
Mode=1	["UTF-8  BOM" Path1 "`r" "UTF-8  BOM" Path2] converted to UTF-8
Mode=2	["UTF-8  BOM" Path1 "`r" "UTF-8  BOM" Path2] converted to UTF-8 (2nd way)
Mode=3	["UTF-16 BOM" Path1 "`r" "UTF-16 BOM" Path2] converted to UTF-8
Mode=4	["UTF-16 BOM" Path1 "`r" "UTF-16 BOM" Path2] converted to UTF-16
Mode=5	[Path1 "`r" Path2] converted to the system's default ANSI code page (CP0).
*/

TC_WMCopyData( Path1, Path2, Flags="", Mode=1 ) {
	Critical
	IF A_IsUnicode	; AutoHotkey Unicode version
		{
		IF	Mode=1
			cmd := Chr(0xEFBBBF) Path1 "`r" Chr(0xEFBBBF) Path2,					VarSetCapacity(cmdA, StrPut(cmd, "UTF-8"), 0),		Len:=StrPut(cmd, &cmdA, "UTF-8")
		Else IF Mode=2
			cmd := Chr(0xEF) Chr(0xBB) Chr(0xBF) Path1 "`r" Chr(0xEF) Chr(0xBB) Chr(0xBF) Path2,	VarSetCapacity(cmdA, StrPut(cmd, "UTF-8"), 0),		Len:=StrPut(cmd, &cmdA, "UTF-8")
		Else IF Mode=3
			cmd := Chr(0xFEFF) Path1 "`r" Chr(0xFEFF) Path2,					VarSetCapacity(cmdA, StrPut(cmd, "UTF-8"), 0),		Len:=StrPut(cmd, &cmdA, "UTF-8")
		Else IF Mode=4
			cmd := Chr(0xFEFF) Path1 "`r" Chr(0xFEFF) Path2,					VarSetCapacity(cmdA, StrPut(cmd, "UTF-16")*2, 0),	Len:=StrPut(cmd, &cmdA, "UTF-16")*2
		Else IF Mode=5
			cmd := Path1 "`r" Path2,								VarSetCapacity(cmdA, StrPut(cmd, "cp0"), 0),		Len:=StrPut(cmd, &cmdA, "cp0")
		}
	Else
		cmd := Path1 "`r" Path2, Len:=StrLen(cmd)+1
	VarSetCapacity( CopyDataStruct, A_PtrSize * 3, 0 )
	NumPut( Asc("C") + 256 * Asc("D"), CopyDataStruct,0 )
	NumPut( Len + 5 * (A_IsUnicode ? 2 : 1), CopyDataStruct, A_PtrSize )
	NumPut((A_IsUnicode ? &cmdA : &cmd), CopyDataStruct, A_PtrSize * 2)
	Loop, % StrLen(Flags)
		NumPut(Asc(SubStr(Flags,A_Index,1)),(A_IsUnicode ? cmdA : cmd),Len+A_Index-1, "Char")
	SendMessage, 0x4A,, &CopyDataStruct,, ahk_class TTOTAL_CMD
}


User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37264
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *ghisler(Author) » 2019-03-14, 15:05 UTC

Is this wrong?
You wrote that it would receive 0x13 (0x means hexademibal), which would be 16+3 = 19 decimal. That's wrong, the code for carriage return is decimal 13 or 0x0D hexadecimal.

I don't think that Chr(0xEFBBBF) is correct. Try sending separate charactes 0xEF, 0xBB, 0xBF.
Author of Total Commander
http://www.ghisler.com

User avatar
artt
Junior Member
Junior Member
Posts: 44
Joined: 2009-05-03, 07:03 UTC

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *artt » 2019-03-14, 16:02 UTC

ghisler(Author) wrote:
2019-03-14, 15:05 UTC
Try sending separate charactes 0xEF, 0xBB, 0xBF.
This is already done in "Mode 2" but it fail to send paths with English characters and paths with Greek characters.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37264
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *ghisler(Author) » 2019-03-14, 16:13 UTC

Here is what I receive:
Mode 3: EF BB BF 0D EF BB BF 00 4C 54
Mode 3: EF BB BF 0D EF BB BF 00 52 54
Mode 5: 0D 00 4C 54
Mode 5: 0D 00 4C 54

Strangely no paths are sent to TC at all. I copied and pasted your above code.

Edit: It seems that I cannot use Hellenic text because I use ANSI file for ahk. Do I need to use Unicode file for this test?
Author of Total Commander
http://www.ghisler.com

User avatar
artt
Junior Member
Junior Member
Posts: 44
Joined: 2009-05-03, 07:03 UTC

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *artt » 2019-03-15, 05:20 UTC

This is very strange!
The code is tested on:
- Windows 10 (1709) x64 + AutoHotkey 1.1.30.01 Unicode x32 + TotalCommander 9.21a x64
- Windows 10 (1709) x64 + AutoHotkey 1.1.30.01 Unicode x32 + TotalCommander 9.21a x32
- File encoding is ANSI: Notepad++=ISO 8859-7, Akelpad=1253 ANSI Greek, TC Lister=Greek (1253)

By what you receive, you are using a Unicode version of AutoHotkey like me.

-- At lines 3,4,5,6 i am setting the paths to sent to TC as variables.

Code: Select all

P1_EN := "D:\__APPS__\"
P1_GR := "D:\__ΕΓΓΡΑΦΑ___\ΑΙΤΗΣΗ-ΔΗΛΩΣΗ-ΕΞΟΥΣΙΟΔΟΤΗΣΗ\"
P2_EN := "C:\FirefoxDownloads\!TC\"
P2_GR := "D:\__ΘΕΜΑΤΑ____\ΔΙΑΣΚΕΔΑΣΗ\ΑΝΕΚΔΟΤΑ\"
-- As the script is running an MsgBox shows the 2 paths that just send to TC and stops for the user to test that paths send correctly.
-- Each transmission send 1st path with English characters and 2nd path with Greek characters.

1. When the MsgBox popup are you seeing the 2 paths readable? Image: https://i.ibb.co/Ntj78mj/Screen-Capture-20190315-065830.jpg
2. Although the script does not check the existance of the paths before send them to TC, what if you replace them with paths that exist in your system?
3. You receive ...Mode 3: EF BB BF 0D EF BB BF 00 4C 54..., but in Mode 3 script sends 0xFEFF !
The BOM EF BB BF is send by Mode 2 that in my tests FAIL to send both English and Greek paths !

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37264
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: HowTo open Dirs in new Tab (WM_COPYData - AutoHotkey)

Post by *ghisler(Author) » 2019-03-15, 13:49 UTC

I pressed the hotkey, received the first wm_copydata in the debugger and saw the first dialog. Then I continued the execution of TC, clicked on your dialog, and received the second message etc. I will have to test this in detail when I have more time, currently I'm unfortunately very busy with the recent update.
Author of Total Commander
http://www.ghisler.com

Post Reply