How to detect context menu in some program?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

How to detect context menu in some program?

Post by 6Tom » 05 Apr 2024, 02:18

Hi dear friends,
I am trying to find a way to check if the context menu exists, or wait for the context menu to appear in Microsoft Edge.

I found this v1 script, but it doesnot seem to work. So I didnot modify it to v2.
(Um, actually I did modify it to v2, but I'm not sure about the usage of NumPut and DllCall. Anyway, it doesn't really matter, neither of them works :crazy: .)

Code: Select all

; https://www.autohotkey.com/board/topic/85769-how-to-detect-existence-of-a-right-click-menuin-any-app/#entry546326
#Requires AutoHotkey v1.1

; based on closeContextMenu() by Stefaan - http://www.autohotkey.com/community/viewtopic.php?p=163183#p163183 
DetectContextMenu()
{
    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
    }
}

I know that ahk_class #32768 can be used to check the context menu in "explorer".
Is there a way to check context menu in Microsoft Edge or other programs?

Return to “Ask for Help (v2)”