Page 1 of 1

[Resolved] Perm variables established outside of XY affected by array changes

Posted: 22 Aug 2022 19:00
by klownboy
Don, the change made to arrays beginning with Beta 23.50.0015 affected perm variables established outside of XYplorer (e.g., AHK) and then sent to XY using copydata (e.g., sending a message to XYplorer). In the Beta notes of 23.50.0015, you mention some global variable work and the fact that perms are not supported in arrays and being ignored. So apparently something in this change affected setting a perm outside of XYplorer as well, like in AHK. It had worked fine since that post about 5 years ago. I tested the beta versions before 23.50.0015 and they worked fine.

Please refer to this post here viewtopic.php?p=202026#p202026 The simple AHK script which set the perm variable and send it to XYplorer is in the first post of that thread, but for ease of viewing I repeat it here. Thanks.

Code: Select all

IfWinActive, ahk_class ThunderRT6FormDC
{
#If (DetectContextMenu() = 1)
{
RButton::
MessagetoXYplorer = ::perm $rmb=1;
SendFunction(MessagetoXYplorer)
click
Return
}
#IfWinActive
}
DetectContextMenu() ; based on closeContextMenu() by Stefaan - http://www.autohotkey.com/community/viewtopic.php?p=163183#p163183
	;https://autohotkey.com/board/topic/85769-how-to-detect-existence-of-a-right-click-menu in-any-app/
{

	GuiThreadInfoSize = 48
	VarSetCapacity(GuiThreadInfo, 48)
	NumPut(GuiThreadInfoSize, GuiThreadInfo, 0)
	if not DllCall("GetGUIThreadInfo", uint, 0, str, GuiThreadInfo)
	{
		MsgBox GetGUIThreadInfo() indicated a failure.
		Return
	}
	; GuiThreadInfo contains a DWORD flags at byte 4
	; Bit 4 of this flag is set if the thread is in menu mode. GUI_INMENUMODE = 0x4
	If (NumGet(GuiThreadInfo, 4) & 0x4)
		Return 1 ; we've found a context menu
	Else
		Return 0
}

SendFunction(MessagetoXYplorer)
{
	HWND := WinExist("ahk_class ThunderRT6FormDC")
	Size := StrLen(MessagetoXYplorer)
	If !(A_IsUnicode) {
		VarSetCapacity(Data, Size * 2, 0)
		StrPut(MessagetoXYplorer, &Data, "UTF-16")
		} Else {
		Data := MessagetoXYplorer
	}
	VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
	NumPut(4194305, COPYDATA, 0, "Ptr")
	NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
	NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
	Result := DllCall("User32.dll\SendMessageW", "Ptr", HWND, "UInt", 74, "Ptr", 0, "Ptr", &COPYDATA, "Ptr")
}

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 12:10
by admin
I don't read AHK. and I don't know what change could affect this.

But if you want to set perm variables from the outside in a running XY you can use the /feed command line switch. It's a bit easier than AHK:

Code: Select all

"C:\Program Files (x86)\XYplorer\XYplorer.exe" /feed=|:: perm $b="hi!"; echo $b;|

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 12:42
by highend
Shortened (and slightly modified) code:

Code: Select all

#IfWinActive, ahk_class ThunderRT6FormDC
{
    ~z::
    MessagetoXYplorer := "::perm $rmb=1;"
    SendFunction(MessagetoXYplorer)
    Return

}
#IfWinActive

SendFunction(MessagetoXYplorer)
{
    HWND := WinExist("ahk_class ThunderRT6FormDC")
    Size := StrLen(MessagetoXYplorer)
    If !(A_IsUnicode) {
        VarSetCapacity(Data, Size * 2, 0)
        StrPut(MessagetoXYplorer, &Data, "UTF-16")
        } Else {
        Data := MessagetoXYplorer
    }
    VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
    NumPut(4194305, COPYDATA, 0, "Ptr")
    NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
    NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
    Result := DllCall("User32.dll\SendMessageW", "Ptr", HWND, "UInt", 74, "Ptr", 0, "Ptr", &COPYDATA, "Ptr")
}
So when it is running and I press "z" in XY, the perm variable is set up...

XY 23.50.01000
AHK 1.1.34.04
Animation.gif
Animation.gif (389.85 KiB) Viewed 1465 times

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 15:25
by klownboy
Hi highend and thanks, it's been a while, but the original purpose of the script is to detect a right mouse button press in a XYplorer context menu at the time it's pressed (i.e., sometimes a user might press the normal left key and other times he might press the right key - this script picks that up). Refer to the original script referenced above. As I mentioned it has worked flawlessly and very responsive since that thread post in 2017. It stopped working with beta 23.50.0015 (thanks to you I pinned pointed it to that beta) which did array work.

Now it may be that I need to change some quoting or other syntax in that original script, to make it work since the beta 23.50.0015, but then again, I'm not sure I should have to since it's worked fine for years. I've changed nothing - no AHK script change, no update to AHK exec or the XYplorer script. An example of a portion of XY script using the right click detection below. The $rmb perm variable is cleared after prior to each use. Thanks.

Code: Select all

"NotePad++<tab>AkelPad|D:\Tools\AkelPad\AkelPad.exe" if ($rmb == 1) {openwith "D:\Tools\AkelPad\AkelPad.exe";}
	else {openwith "D:\Tools\NotePad++\notepad++.exe"}

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 18:16
by klownboy
admin wrote: 23 Aug 2022 12:10 I don't know what change could affect this
It was without a doubt the changes made in beta 23.50.0015. It worked fine for years before that up to and including 23.50.0013.
admin wrote: 23 Aug 2022 12:10 It's a bit easier than AHK:
But in this case, AHK is needed because we have to detect if a context menu is up or running. In this case a context menu within XY. If there's a context menu and then a right click is detected within the context menu, a perm variable, $rmb is set. The perm is then used in XYplorer script to set a course of action based on whether a normal left click is made or a right click.

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 18:24
by admin
The command ::perm $rmb=1; works as it always did. I don't see what could have affected your AHK.

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 18:56
by highend
Tested your script from the first post. Apart from the problem that it's 32 bit only it works as expected. Right clicking on a context menu leads to a defined perm var...

Re: Perm variables established outside of XY affected by array changes

Posted: 23 Aug 2022 20:30
by klownboy
highend wrote: 23 Aug 2022 18:56 Tested your script from the first post. Apart from the problem that it's 32 bit only it works as expected. Right clicking on a context menu leads to a defined perm var...
Thanks highend for checking. Based on that, I checked also and yes it worked. Both of my most commonly used ones are triggered by right click on white in list and another in tree. It may be that these are triggered via CEA..I'm guessing...only because one runs fine from "Load script file" or a Customized File Association. Odd, more checking to do obviously, but what makes it odder is that they always worked before 23.50.0015.

Re: Perm variables established outside of XY affected by array changes

Posted: 25 Aug 2022 11:50
by klownboy
After some more testing I figured out why my scripts failed from beta version 23.50.0015 on. Unsetting $rmb in the beginning of the script worked in 23.50.0013 and earlier. From 23.50.0015 on it, unsetting $rmb results in a script failure. The variable $rmb ends up being "" so the script gives an error since if ($rmb="1") {... results in "if(==1) {..." See mini version of script below.

So for some reason in beta 23.50.0015 and on, the unset $rmb up front affects what comes later when AHK is detecting the right click in the context menu and setting $rmb="1". Now I realize that unsetting the variable up front was probably not necessary since I unset in "_Terminate", but it does seem strange that the unset in the beginning of the script would now cause the script to fail. Afterall, the right click detect does not occur until the context menu is clicked. Don, would 23.50.0015 have altered that perm variable set sequence in some way unintentionally? Thanks.

Code: Select all

// WhiteSpaceCtxMenu_test
// Unsetting $rmb in the next line worked in 23.50.0013.  From 23.50.0015 on it, unsetting $rmb results in a script failure.
// The variable $rmb ends up being "" so the script gives an error since if ($rmb="1") {... results in "if(==1) {..."
// So for some reason in beta 23.50.0015, unsset $rmb affects what comes later where AHK is detecting the right click
// in the context menu and setting $rmb="1"

	unset $rmb;   //this unset of $rmb causes the script to fail
	perm $mod, $loc;
	$mod = get("shift");
	$loc = ControlatPos();

	$FavFolders = <<<FAVS
"Home [C:\]<tab>Downloads|:home" if($rmb=="1") {goto "G:\Downloads\";}
	else {#1401;}
"Wallpaper<tab>Photos  📷|D:\Graphics\Icons\wallpaper_08.ico" if($rmb=="1") {goto "H:\Pictures\"}
	else {goto "G:\Wallpaper\1920x1080\";}
"XY scripts<tab>AHK scripts  🅰️|D:\Graphics\Icons\xy.ico" if($rmb=="1") {goto "D:\Tools\AutoHotkey\AHKscripts\";}
	else {goto "D:\Tools\XYplorer\Scripts\";}
"Agent DLs<tab>Tools  🛠️|D:\Graphics\Icons\agent.ico" if($rmb=="1") {goto "D:\Tools\";} else {goto "G:\Agent downloads\";}
"XYmenu<tab>Pics && Walls  🌷|XY light.ico" if($rmb=="1") {load "<xyscripts>\ThumbnailViewer_exec_L_Photos_R_Wallpaper.xys";} else {load "<xyscripts>\XYmenu_NESTED.xys";}
"RegEdit<tab>GPedit  ⚙️|C:\Windows\regedit.exe" if($rmb == '1') {open "gpedit.msc";}
	else {open "C:\Windows\regedit.exe";}
"Control Panel<tab>Task Manager  ™|C:\Windows\System32\taskmgr.exe" if($rmb == '1') {open "C:\Windows\System32\taskmgr.exe";} else {#640;}
"Cards && Games<tab>Photo Crop  ✂|:ghost" if($rmb=="1") {load "<xyscripts>\PhotoCrop_both_axis_01.xys";} else {load "D:\Tools\XYplorer\Scripts\cards&games_left.xys";}
FAVS;

/*** Copy/Move/New menu ***/
//"Caption|Icon|State|Level 
	$copymove = <<<COMO
"To clipboard|:clip||"
"Item path/name(s)|:cliptext||1" #101;
"Item name(s)|:cliptext||1" #102;
"Image|D:\Graphics\Icons\image eye.ico||1" #115;
"Copy<tab>Move  🐇|:copyto||1" if ($rmb == 1){#4;} else {#5;}
"New folder<tab>New file  📂|:newfolder" if ($rmb == "1"){#234;} else {#231;};
COMO;

	if($loc == "T") {
			if ($mod == 0) {load "$FavFolders<crlf>-<crlf>$copymove"; end 1;} //			if ($mod == 0) {load "$FavFolders<crlf>-<crlf>$copymove", ,s; end 1}
			else {load "<xyscripts>\XYmenu_NESTED.xys", ,s; end 1;}
	}

	elseif(gettokenindex($loc, "L 1|L 2", "|", "i")) {
				load "$FavFolders<crlf>-<crlf>$copymove", ,s; end 1;
	}
"_Terminate";
	unset $mod, $loc, $rmb;

Re: Perm variables established outside of XY affected by array changes

Posted: 25 Aug 2022 12:18
by admin
Thanks, that helped! :tup: It was indeed a bug from 20220815 onwards. Fixed in next beta.

Re: Perm variables established outside of XY affected by array changes

Posted: 25 Aug 2022 12:23
by klownboy
Great Don, thanks. :tup: :appl: