Jump to content

how to automate clicking an item on the right click drop down menu

Recommended Posts

Hi ,

I am working on a gui which involves arranging items by drag and drop. The variables respective to each item can be changed by right clicking on the item and choosing an option from the drop down menu. Now since drop down menu doesn't have a title bar  how do i get hold of the sub items in the menu?? Please help guys .. Thanks in advance . :) 

Link to post
Share on other sites

Just right-click where you need (to make context menu appear) a then run this function:

#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>

Func Click_RightClickMenu($sRequired_Text = "")
    Local $previousMousePos, $hWnd, $hMenu, $iCount, $iIndex, $sText, $aPos, $iOldOpt
    $previousMousePos = MouseGetPos()
    If $sRequired_Text = "" Then Return SetError(1)
    If WinExists("[CLASS:#32768]") Then
        $hWnd = WinGetHandle("[CLASS:#32768]")
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $iIndex = 0 To $iCount - 1
                $sText = StringReplace(_GUICtrlMenu_GetItemText($hMenu, $iIndex),"&","")
                If $sText == $sRequired_Text Then
                    $aPos = _GUICtrlMenu_GetItemRect($hWnd, $hMenu, $iIndex)
                    $iOldOpt = Opt("MouseCoordMode", 0)
                    MouseClick("primary", $aPos[0] + ($aPos[2] - $aPos[0]) / 10, $aPos[1] + ($aPos[3] - $aPos[1]) / 2, 1, 1)
                    Opt("MouseCoordMode", $iOldOpt)
    MouseMove($previousMousePos[0], $previousMousePos[1], 0)
EndFunc   ;==>Click_RightClickMenu

Where $sRequired_Text - is the name of the menu item you want to click

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...