Windows 11 Classic Context Menu via Right-Double-Click

Post your working scripts, libraries and tools for AHK v1.1 and older
JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Windows 11 Classic Context Menu via Right-Double-Click

24 Oct 2023, 15:23

I thought I'd share this short one: while running, it displays any Explorer item's "classic" extended context menu when the item is double-clicked using the secondary mouse button (right-single-click still has the expected behavior, and right-drag & drop shouldn't be affected). This provides a single-handed alternative to Shift + Right-Click (and the code might be useful if you'd like to assign other actions to Right-Double-Click in your own programs, assuming my detection method isn't too idiotic! ;-)) [You'll need to provide your own RButton.ico & LButton.ico icon files for use in the tray to compile or execute this code without modification]

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

Skrell
Posts: 307
Joined: 23 Jan 2014, 12:05

Re: Windows 11 Classic Context Menu via Right-Double-Click

26 Oct 2023, 15:50

What's with the Ahk2Exe-PostExec stuff?
JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: Windows 11 Classic Context Menu via Right-Double-Click

26 Oct 2023, 18:05

Gets rid of unnecessary icons in the resulting executable (the program only uses two icons). Remove those lines if you don't care, or correct the path to wherever you keep ResHacker.exe ("Resource Hacker", from angusj.com)

JB

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 96 guests