DLS Posted March 2, 2017 Share Posted March 2, 2017 (edited) 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 March 2, 2017 by DLS Link to comment Share on other sites More sharing options...
InnI Posted March 2, 2017 Share Posted March 2, 2017 5 hours ago, DLS said: Is there a way to get any of the other methods to work? ConsoleWrite(ControlCommand($hWnd, "", "Edit1", "SendCommandID", $iID) & @CRLF) ;trying to invoke context menu item here 5 hours ago, DLS said: Also is there a way to invoke the right click menu besides Send("{APPSKEY}") ControlClick($hWnd, "", "Edit1", "right") Link to comment Share on other sites More sharing options...
junkew Posted March 2, 2017 Share Posted March 2, 2017 Why? Sendmessage postmessage command can help FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
DLS Posted March 3, 2017 Author Share Posted March 3, 2017 (edited) 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 March 3, 2017 by DLS Link to comment Share on other sites More sharing options...
InnI Posted March 3, 2017 Share Posted March 3, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now