Page 2 of 2

Re: Middle mouse button - customisable popup menu

Posted: 2020-04-29, 19:30 UTC
by Hacker
I have created a quick and dirty middle mouse button menu tool in AHK, similar to QAP but much much more basic. It consists of two files, MouseMenu.ahk, which is the actual script, which reads in MouseMenuConfig.ahk where all the relevant window classes (ahk_class) and script snippets to execute are defined. The user changes MouseMenuConfig.ahk to his liking.

MouseMenu.ahk:

Code: Select all

#Include, MouseMenuConfig.ahk

FileRead, Code, MouseMenuConfig.ahk

MButton::
	Found := False

	MouseGetPos, MouseX, MouseY, WinUnderMouse
	WinActivate, ahk_id %WinUnderMouse%
	WinGetClass, ActiveWinClass, ahk_id %WinUnderMouse%

	Loop, Parse, Code, `n, `r
		If (InStr(A_LoopField, "MenuFunction" . CommandNameDelimiter . "ahk_class" . SpaceReplacement . ActiveWinClass) = 1)
		{
			If (Found = False)
			{
				Gui, MouseMenu: New, -Caption
				Gui, MouseMenu: Margin, 0, 0
				Found := True
			}
			Gui, MouseMenu: Add, Button, gButtonClicked, % StrReplace(SubStr(A_LoopField, InStr(A_LoopField, CommandNameDelimiter, , , 2) + StrLen(CommandNameDelimiter), -2), SpaceReplacement, " ")
		}

	Gui, MouseMenu: Show, X%MouseX% Y%MouseY%
Return

#IfWinActive, ahk_class AutoHotkeyGUI
MButton::
Esc::Gui, MouseMenu: Destroy

ButtonClicked()
{
	global SpaceReplacement
	global CommandNameDelimiter
	global WinUnderMouse
	global ActiveWinClass
	FunctionToCall := % "MenuFunction" . CommandNameDelimiter . "ahk_class" . SpaceReplacement . ActiveWinClass . CommandNameDelimiter . StrReplace(A_GuiControl, " ", SpaceReplacement)
	Gui, Destroy
	WinActivate, ahk_id %WinUnderMouse%
	%FunctionToCall%()
}
MouseMenuConfig.ahk (example):

Code: Select all

SpaceReplacement := "___"
CommandNameDelimiter := "_#_"

MenuFunction_#_ahk_class___TTOTAL_CMD_#_Edit___Files()
{
	Send, {F4}
}
MenuFunction_#_ahk_class___TTOTAL_CMD_#_Copy___Files()
{
	Send, {F5}
}
MenuFunction_#_ahk_class___TTOTAL_CMD_#_Move___Files()
{
	Send, {F6}
}
MenuFunction_#_ahk_class___MozillaWindowClass_#_Reload()
{
	Send, ^r
}
MenuFunction_#_ahk_class___MozillaWindowClass_#_Next___Tab()
{
	Send, ^{Tab}
}
I hope it's more or less self-explanatory.

HTH
Roman

Re: Middle mouse button - customisable popup menu

Posted: 2020-04-30, 05:02 UTC
by nsp
I jump a bit late but i personally used powerpro with context menu integration (Right Click) to create dedicated menus for mousse addict.

You can create inside powerpro a dedicated section for TotalCommander "context File"/ context Folder and use tcfs tools to send command...
The bigest advantage, is that you know witch file is under the cursor and can do filtering to have contextual menu parts (Archive,Image....)

Learning curve of powerpro is not ultra fast and the current status is mot in active development but if you are a programmer it's woth a try. Support group is not on yahoo anymore...
The Bible for PowerPro and TC is http://ppro.totalcmd.net/ you can find a sample context menu sample if you search "context" .