Code: Select all
; === Start of Compiler Directives ===
;
;@Ahk2Exe-Base Ansi 32-bit.bin, CCMenu.exe
;
;@Ahk2Exe-SetMainIcon RButton.ico ; Icon group 1
;@Ahk2Exe-AddResource LButton.ico, 160 ; Icon group 2
;
;@Ahk2Exe-PostExec "C:\Utility\ResHack\ResHacker.exe" -delete "%A_WorkFileName%"`, "%A_WorkFileName%"`, icongroup`, 208`,
;@Ahk2Exe-PostExec "C:\Utility\ResHack\ResHacker.exe" -delete "%A_WorkFileName%"`, "%A_WorkFileName%"`, icongroup`, 207`,
;@Ahk2Exe-PostExec "C:\Utility\ResHack\ResHacker.exe" -delete "%A_WorkFileName%"`, "%A_WorkFileName%"`, icongroup`, 206`,
;
; ==== End of Compiler Directives ====
#SingleInstance Force
SetBatchLines, -1
CoordMode, Mouse, Screen ; unnecessary but harmless
ProgName := "Classic Context Menu"
RegRead, Swap, HKCU\Control Panel\Mouse, SwapMouseButtons ; missing value automatically treated as FALSE
If !A_IsCompiled
Menu, Tray, Icon, % A_ScriptDir "\" (Swap ? "L" : "R") "Button.ico"
Else
{
Menu, Tray, UseErrorLevel ; to catch any menu-related errors
Menu, Tray, NoStandard ; prepare for custom context menu
Menu, Tray, Icon, %A_ScriptFullPath%, % Swap ? 2 : 1
ListLines, Off ; might improve performance?
}
Menu, Tray, Add, Restart %ProgName%, mRestart
Menu, Tray, Icon, Restart %ProgName%, Shell32.dll, 239
Menu, Tray, Add, Exit %ProgName%, mExit
Menu, Tray, Icon, Exit %ProgName%, Shell32.dll, 131
Menu, Tray, Tip, Windows 11 %ProgName%:`n`nRight-double-click Explorer items to`ndisplay their classic context menu.
ButtonDown := (Swap ? "{L" : "{R") "Button Down}"
ButtonUp := (Swap ? "{L" : "{R") "Button Up}"
RegRead, DCSpeed, HKCU\Control Panel\Mouse, DoubleClickSpeed
If (ErrorLevel)
DCSpeed := 500
SetKeyDelay, -1
InRC := FALSE ; keeps track of first right-click (FALSE) or second (TRUE)
Return
; =============
; Menu Handling
; =============
mRestart:
Reload
Return
mExit:
ExitApp, 0
; =======
; Hotkeys
; =======
#If MouseOnFolder() ; limited to known Explorer folder window classes
RButton:: ; necessary to allow right-drag (in the presence of a matching UP hotkey)
Send, %ButtonDown%
Return
#MaxThreadsPerHotkey 2 ; the next hotkey needs to be available twice simultaneously
RButton UP::
If (InRC) ; has a first righ-click been seen?
{
If (A_TickCount - Tick1 < DCSpeed) ; was it recent enough to qualify as a double-click?
Click := "+{Click Right}" ; prepare to use Shift + Right-Click to display the classic context menu
}
Else
{
Tick1 := A_TickCount, InRC := TRUE ; record the tick count on a first right-click
Sleep, %DCSpeed% ; wait long enough to allow for a double-click
If (InRC)
Click := ButtonUp ; it wasn't, so prepare to release the button to display the default context menu
}
InRC := FALSE ; an action is about to be performed, so we no longer have a pending right-click to arbitrate
WinGet, aID, ID, A ; make sure the window under the mouse is the active one
If (aID != wID)
WinActivate, ahk_id %wID%
Send, %Click% ; perform whichever action was determined above
Return
#MaxThreadsPerHotkey 1
#If
MouseOnFolder() ; used to limit the hotkeys to Explorer folder windows (and stores the ID of the window under the mouse)
{
global wID
MouseGetPos,,, wID
WinGetClass, wClass, ahk_id %wID%
Return, RegExMatch(wClass, "S)^(CabinetWClass|Progman|WorkerW)$")
}