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
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", ©DATA, "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
}