Jump to content

How to invoke option in right click menu


 Share

Recommended Posts

 Here's an easy to follow sample code.

#include <GuiMenu.au3>

Run("notepad.exe")
$hWnd = WinWaitActive("[CLASS:Notepad]")
Send("{APPSKEY}")
 If WinExists("[CLASS:#32768]") Then
    $hMenu = _GUICtrlMenu_GetMenuBarInfo(WinGetHandle("[CLASS:#32768]"), 0, 0)
      $iCount = _GUICtrlMenu_GetItemCount($hMenu[4])
      For $iItem = 0 To $iCount-1 Step 1
         $iID = _GUICtrlMenu_GetItemID($hMenu[4], $iItem, True)
         $iText =  _GUICtrlMenu_GetItemText($hMenu[4], $iID, False)
         ConsoleWrite("Item=[" & $iItem & "]  ItemID=[" & $iID & "]  text=[" & $iText & "]" & @CRLF)    ;console write all rightclick menu options
         If $iText = "&Paste" then
           ConsoleWrite(_GUICtrlMenu_SetItemID($hMenu,$iItem,$iID)& @CRLF)                              ;trying to invoke context menu item here
           ConsoleWrite(ControlCommand($hMenu,"","[CLASS:#32768]","SelectString",$iText) & @CRLF)       ;trying to invoke context menu item here
           ConsoleWrite(ControlCommand($hMenu,"","[CLASS:#32768]","SendCommandID", $iID) & @CRLF)       ;trying to invoke context menu item here
           ConsoleWrite(WinMenuSelectItem($hMenu,"",$iText)& @CRLF)                                     ;trying to invoke context menu item here
           For $i =0 to $iCount-1 step 1
              Send("{DOWN}")                                                                            ;sucessfully invoking item, seems crude
           Next
            Send("{Enter}")
         EndIf
      Next
 EndIf

As you can see, the only thing working is sending keyboard commands.  Is there a way to get any of the other methods to work?

Also is there a way to invoke the right click menu besides Send("{APPSKEY}")

Edited by DLS
Link to comment
Share on other sites

19 hours ago, InnI said:
ConsoleWrite(ControlCommand($hWnd, "", "Edit1", "SendCommandID", $iID) & @CRLF)       ;trying to invoke context menu item here

 

Thanks for the help/

Your approach only works for the right click menu in notpad.

Heres a simplified version of my actual code.

#include <GuiMenu.au3>
#Include <GuiListView.au3>
    
Run("C:\Windows\System32\control.exe mmsys.cpl")
$hWnd = WinWaitActive("Sound")
WinActivate("[CLASS:SysListView32]")
$hList = ControlGetHandle($hWnd, "", "[CLASS:SysListView32]")
_GUICtrlListView_SetItemSelected($hList, 0)                                                                    ;selects first item in the list
Send("{APPSKEY}")                                                                                            ;right click menu
$hMenu=_GUICtrlMenu_GetMenuBarInfo(WinGetHandle("[CLASS:#32768]"), 0, 0)
$iCount = _GUICtrlMenu_GetItemCount($hMenu[4])
For $iIndex  = 0 To $iCount-1 Step 1
   $itemID   =  _GUICtrlMenu_GetItemID($hMenu[4], $iIndex, True)
   $itemText   =  _GUICtrlMenu_GetItemText($hMenu[4], $itemID, False)
   ConsoleWrite("Item=[" & $iIndex & "]  ItemID=[" & $itemID & "]  text=[" & $itemText & "]" & @CRLF)    ;debug - console write all rightclick menu options
   If $itemText = "Disable" then
;~       For $i =0 to $iIndex step 1                                                                    ;works
;~          Send("{DOWN}")
;~       Next
;~       Send("{Enter}")
      ControlCommand($hWnd, "", "Edit1", "SendCommandID", $itemID)                                    ;does not work
      ControlCommand($hWnd, "", "", "SendCommandID", $itemID)                                         ;works
   EndIf
Next

The rightclick menu I am calling is not called "Edit1".  It was actually called nothing.

 To make it more universal, is there a function I can call the returns that "Edit1" given the handle of the right click menu for furture use? 

Edited by DLS
Link to comment
Share on other sites

5 hours ago, DLS said:

only works for the right click menu in notpad

Your question was about notepad and I naturally responded about notepad.

 

5 hours ago, DLS said:

is there a function I can call

_GUICtrlListView_ClickItem($hList, 0, "right")

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...