Right Mouse Click functions in XYplorer menus

Discuss and share scripts and script files...
Post Reply
klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Right Mouse Click functions in XYplorer menus

Post by klownboy »

Hi, today I'm posting an AHK script, which you can run at start-up (or anytime), along with a sample XYplorer script which will recognize and execute both a normal left click of the mouse and a right click. If you already use AHK like many XYplorer users, you can simply insert the AHK code in your existing AHK startup code or run it separately.

The AHK code above detects when a right click is accomplished on an XYplorer menu/ctx menu. If the checks are true (i.e., XY is active and the user right mouse clicks on a context menu), then a XY permanent variable is created. At this point, the AHK script then sends a normal left mouse click to the XYmenu item. In the XYplorer script, we differentiate between the normal left click of the menu and the right click by the fact that the permanent variable is set. The AHK script is not involved when the user performs a normal left click of the mouse (i.e., the above action is taken for the right click only).

One most obvious example for its use in an XY menu script is being able to execute the normal action of an XYplorer built-in toolbar button with the left mouse button and the button's context menu with the right mouse button - as seen for menu item Touchscreen Mode and Preview Pane below. Similarly, you can also execute left and right mouse actions of your Customized Toolbar Buttons. You could assign totally different actions to the left & right mouse buttons. You should be able to cut down the size of some menus by being able to provide left and right actions. Most importantly, I notice no lag once-so-ever, the right click mouse actions execute as fast as the left. See the example XYplorer menu below.

I'm using the standard Ansi version of Autohotkey. https://autohotkey.com/ I believe the AHK script will work with the Unicode version as well, but I'm not sure about the 64 bit version.

Sample script - XYmenu_using_L&R_mouse_buttons.xys

Code: Select all

"_MENU";   //Sample script - XYmenu_using_L&R_mouse_buttons.xys

"Touchscreen Mode|:tsm" if($RightClickDetect == '1') {button "tsm", 2; } else {#315;}
"Preview Pane|:pp" if !($RightClickDetect == '1') {#674;} else {button "pp", 2; }
"Control Panel [L]  Device Manager [R]|:conf" if($RightClickDetect == '1')
	{open "C:\Windows\System32\devmgmt.msc";}
	else {run "%windir%\explorer.exe shell:::{ED7BA470-8E54-465E-825C-99712043E01C}";}
"CKS [L]  CTB [R]|:cks" if($RightClickDetect == '1')
	{#603;}
	else {#602;}
"Cards [L]  Games [R]|:ghost" if($RightClickDetect == '1')  //just an example; it will not work for you
	{userbutton 12, 1}
	else {userbutton 1, 2}  
"Task Manager [L]  Services [R]|C:\Windows\System32\taskmgr.exe" if($RightClickDetect == '1')
	{run "services.msc";}
	else {open "C:\Windows\System32\taskmgr.exe";}

"_Terminate";
	unset $RightClickDetect;   //clear the perm variable before the next run
AHK script - Detect_right_click_XY.ahk

Code: Select all

#SingleInstance force
;#NoTrayIcon

IfWinActive, ahk_class ThunderRT6FormDC
{
															
#If (DetectContextMenu() = 1)
RButton::
MessagetoXYplorer = ::perm $RightClickDetect=1;
SendFunction(MessagetoXYplorer)
click
Return
#If
}

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

DetectContextMenu() ; based on closeContextMenu() by Stefaan - http://www.autohotkey.com/community/viewtopic.php?p=163183#p163183
{
	   
	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
}
Screen shot of the sample XYplorer menu.
XYmenu_using_L&R_Mouse Buttons.JPG
XYmenu_using_L&R_Mouse Buttons.JPG (16.91 KiB) Viewed 5101 times
I hope you can get some use out of it. Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Right Mouse Click functions in XYplorer menus

Post by jupe »

Nice work getting this to work, one thing I found out recently that you may already know about but I found useful is that if you put a <tab> in the caption it right aligns the second part of the caption which might be desirable in this use case.

eg.

Code: Select all

"Control Panel [L]<tab>Device Manager [R]|:conf"
"CKS [L]<tab>CTB [R]|:cks"
"Cards [L]<tab>Games [R]|:ghost"
Here's a screenshot (hopefully it shows up this time)

Image

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Right Mouse Click functions in XYplorer menus

Post by klownboy »

jupe wrote:one thing I found out recently that you may already know about but I found useful is that if you put a <tab> in the caption it right aligns the second part of the caption which might be desirable in this use case.
Actually no, I didn't know that. I experimented a bit inserting tabs via my text editor, but I didn't try inserting a tab character <tab>. When setting up the menu with right click action right-aligned, I'm not sure if it's even necessary to have the [L] and [R] abbreviations. Or another thought, it seems to look a bit neater if you place the [L] symbol on the outer left edge. So the [L]'s are all on the outer left, and the [R]'s are on the outer right side. Thank you for the tip and comment. Now if we could only get an icon for the right side action. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Right Mouse Click functions in XYplorer menus

Post by jupe »

I just copied the captions from your initial example so as to post a quick screenshot along with my reply comment, and I thought the same as you afterwards about the [L] & [R] but didn't bother re-doing the screenshot, glad the tip was useful to you though.

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Right Mouse Click functions in XYplorer menus

Post by jupe »

I had another think about what you said about having right aligned icons, and it's not perfect but you may like it, you could use Unicode icons in the caption to recieve a similar effect, although from me just testing it quickly they only turn up in monochrome.

I just grabbed a couple random ones from https://emojipedia.org but there are heaps of options, so you may find something close to what you want.

Attached is a screenshot of how it came out anyway
xy_rclick_emoji.png
xy_rclick_emoji.png (3.77 KiB) Viewed 5065 times

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Right Mouse Click functions in XYplorer menus

Post by klownboy »

Again nice idea. I'm all for functionality along with a nice look. It initially didn't work for me. I had forgotten that the file was saved in Ansi. Now it's saved as UTF-8 with BOM. Is that the format you save your scripts? A few of the symbols don't display in my editor Akelpad, but they display properly on the screen.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Right Mouse Click functions in XYplorer menus

Post by jupe »

Usually I just use ANSI, but in this case because of the Unicode icons I switched the encoding, I should have mentioned it. I use Notepad3 for editing scripts and the chars display okay in it once the encoding is set.

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Right Mouse Click functions in XYplorer menus

Post by klownboy »

I'm still thinking about alignment, but I can't achieve what I want exactly. I was hoping someone could help me. Maybe it's not the right place to ask, but since the background is here I'll start here. Is there any way to get an alignment like 2 columns both left aligned in an XYplorer menu similar to what I have below. I had to use spaces to get approximately alignment. When you insert a tab in the text editor or a tab character, <tab>, you get right-side alignment as jupe screen capture depicts above.
Thanks for any help.
XY_Left & Right click Menu.JPG
XY_Left & Right click Menu.JPG (34.7 KiB) Viewed 5021 times
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Right Mouse Click functions in XYplorer menus

Post by highend »

Probably not possible without changing the way (through Don) how such
a menu is displayed. It's not a monospace font in the menu so trying to
align right hand side items on it's leftmost position will never be accurate...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Right Mouse Click functions in XYplorer menus

Post by klownboy »

Oh well, thanks highend. I figured I'd ask but I really didn't think it would be possible. I know you can build that kind of alignment in a text box using a combination of SC Substr and StrRepeat, but a text box and a menu are two different things. It's too bad you can't tab in the text editor to achieve column type alignment like you typically can - instead of right-hand alignment. So normal tabbing in the text editor would be displayed in XYplorer as a normal tab whereas the tab character, <tab> would achieve right-hand alignment. Does that make sense or would it make sense to ask Don?
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Right Mouse Click functions in XYplorer menus

Post by highend »

I would ask Don what's possible inside the menu. Subclassing it would probably
a way but that's most of the time a can of worms so I don't know if he wants
to invest any time on improving it...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Right Mouse Click functions in XYplorer menus

Post by klownboy »

This script no longer works . The perm variable set via the AHK and sent to XYplorer via MessagetoXYplorer = ::perm $RightClickDetect=1;
SendFunction(MessagetoXYplorer)
The perm variable in this case $RightClickDetect is empty so the check to see if it was a right click done If($RightClickDetect == "1") {...} is never true.

Don I just noticed this yesterday (Aug 19, 2022). Was there a change to perms or something that could affect perms in the last few days or maybe a week. I would have noticed it if it was more than that. It has worked for the last 5 years since this original post.

Jupe and highend, I know you were involved with this as well. Though I don't know if you actively use it now. If possible, could you cross check it.

EDIT: I went back to previous version 23.40 and this worked properly as it always had. I suspect it may be the changes concerning arrays and globals that may have affected the perm used in this case. I'll see if I can narrow it down further to a beta.

Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

LostFirefox36
Posts: 6
Joined: 15 Aug 2019 00:21

Re: Right Mouse Click functions in XYplorer menus

Post by LostFirefox36 »

klownboy wrote: 20 Aug 2022 19:16 EDIT: I went back to previous version 23.40 and this worked properly as it always had. I suspect it may be the changes concerning arrays and globals that may have affected the perm used in this case. I'll see if I can narrow it down further to a beta.

Thanks.
Any luck figuring this out? I have also been using the Function listed above to send commands to XyPlorer from autohotkey, for probably 3-4 years now and have it integrated into a lot of my daily autohotkey scripts/shortcuts. I'm going to revert to 23.40 for now as well.

I got the original script from here: viewtopic.php?f=7&t=9233

Edit: Found a script on the Autohotkey forums that works, even with the newest version: https://www.autohotkey.com/board/topic/ ... pt-to-ahk/

Edit2: Turns out the issue was with version 23.40 and 23.50, I updated to 23.60 and my old scripts work again.

Post Reply