Zohar Posted February 11, 2012 Share Posted February 11, 2012 (edited) Hi I am trying to Automate an application where when RightClicking it, some times the ContextMenu opens, and sometimes it doesn't, and need another RightClick to succeed. Is there any way to know when a ContextMenu opens? Thank you Edited February 17, 2012 by Zohar Link to comment Share on other sites More sharing options...
IanN1990 Posted February 11, 2012 Share Posted February 11, 2012 Have u tryed using the Window Info on it ? If u get a window title or class name, then u can just do a check like "if winexists"? Link to comment Share on other sites More sharing options...
Zohar Posted February 12, 2012 Author Share Posted February 12, 2012 Hi Ian The AutoIt Window Info Tool does not see open menus.As If they are not a window..If anyone has a trick here, it would really help me,because not always when I ask to open a Menu, it is indeed opened..So I need a way to verify it, to make my code more robust.. Link to comment Share on other sites More sharing options...
Fixis Posted February 12, 2012 Share Posted February 12, 2012 Hi Zohar, I am new to Autoit but I hope to be able to help. The ContextMenu is considered a window, you can try to find out how many windows are there before the click and then after the click, if the number is the same the ContextMenu is not open if they are more after the click the ContextMenu is open. You can use this code to find out how many windows are there: Local $var = WinList() MsgBox(0, "Window Number", Ubound($var) ) Ubound($var) can be used for the comparison Link to comment Share on other sites More sharing options...
Guest Posted February 12, 2012 Share Posted February 12, 2012 What is the application that you are attempting this with. Because the ContextMenu might be custom made therefore it might not be a window but using PixelSearch function could help. Link to comment Share on other sites More sharing options...
Zohar Posted February 13, 2012 Author Share Posted February 13, 2012 Hi FixisThat's definately a creative idea..If indeed a ContextMenu is a Window, then it should work,however there's one problem with is: If another window (which is not the ContextMenu) opens during the time I wait for the ContextMenu to open,then my script wil be wrong, thinking the ContextMenu opened.So it's not a deterministic method for knowing.(but I will definitely remember it for other places where coutnring the number of windows might help)BTW during the past day, I thought about a way to solve my problem here:Instead of opening the ContextMenu, and then moving with the arrows and selecting the appropriate MeniItem, and then simulating [Enter],I am going to try something else:To capture the Windows Message that is sent when clicking the appropriate MenuItem,and then to simulate that Windows Message.That way, I can achieve the functionality I wanted, without even opening the ContextMenu!Hi Aipion.the appliction is TeamViewer.Whenever I use TeamViewer, there're some operations that I usually do at the beginning,like Change Resolution of target machine,Change Quality,and move to Full Screen.So I want all these operations to be done on the beginning, automatically.I will post here If I managed to do it via SendMessage()Thank you bothZohar Link to comment Share on other sites More sharing options...
Guest Posted February 13, 2012 Share Posted February 13, 2012 Hi Zohar, You can use the code below to know when the ContextMenu is opened. #include <GuiMenu.au3> While 1 Sleep(10) If WinActive("TeamViewer") Then ;Makes sure not any active ContextMenu is accepted If WinExists("[CLASS:#32768]") Then ;Makes sure it is a ContextMenu. $SomeName = _GUICtrlMenu_GetMenuBarInfo(WinGetHandle("[CLASS:#32768]" ), 0, 0) MsgBox(64,"Information about the current ContextMenu",$SomeName[0]&" - X coordinate of the upper left corner of the rectangle"&@CRLF& _ $SomeName[1]&" - Y coordinate of the upper left corner of the rectangle"&@CRLF& _ $SomeName[2]&" - X coordinate of the lower right corner of the rectangle"&@CRLF& _ $SomeName[3]&" - Y coordinate of the lower right corner of the rectangle"&@CRLF& _ $SomeName[4]&" - Handle to the menu bar or popup menu"&@CRLF& _ $SomeName[5]&" - Handle to the submenu"&@CRLF& _ $SomeName[6]&" - True if the menu bar has focus, otherwise False"&@CRLF& _ $SomeName[7]&" - True if the menu item has focus, otherwise False"&@CRLF) EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
Zohar Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) Hi AipionThis works amazing.Thank you very much for it.I would like to ask you something:The AutoIt Window Info tool, doesn't "see" menus. So how did you find it?And also:Is there any way to verify that the Menu that I found(in code), is indeed the menu I am looking for?For example by getting its first MenuItem, and comparing the Text init to see that it's indeed what I'm expacting for?Thank you verymuchZohar Edited February 14, 2012 by Zohar Link to comment Share on other sites More sharing options...
Guest Posted February 14, 2012 Share Posted February 14, 2012 (edited) I would like to ask you something: The AutoIt Window Info tool, doesn't "see" menus. So how did you find it? When you run the tool and unfreeze it then click on the menu button that you want to get info of, you will see the menu drop just then the Info tool will pick up the menus class. you just use that class to know when the menu gets opened. And also: Is there any way to verify that the Menu that I found(in code), is indeed the menu I am looking for? For example by getting its first MenuItem, and comparing the Text init to see that it's indeed what I'm expacting for? This code will help. #include <GuiMenu.au3> While 1 Sleep(10) If WinActive("TeamViewer") Then ;Makes sure not any active ContextMenu is accepted If WinExists("[CLASS:#32768]") Then ;Makes sure it is a ContextMenu. $ContextMenuWin = WinGetHandle("[CLASS:#32768]" ) ;Handle of the ContextMenu window $SomeName = _GUICtrlMenu_GetMenuBarInfo($ContextMenuWin, 0, 0) $iText = "" For $I = 0 To _GUICtrlMenu_GetItemCount($SomeName[4]) -1 $iText &= $I&" = " & _GUICtrlMenu_GetItemText($SomeName[4], $I, True) & @CRLF Next MsgBox(0, "All the Items in the current ContextMenu",$iText) MsgBox(64,"Information about the current ContextMenu",$SomeName[0]&" - X coordinate of the upper left corner of the rectangle"&@CRLF& _ $SomeName[1]&" - Y coordinate of the upper left corner of the rectangle"&@CRLF& _ $SomeName[2]&" - X coordinate of the lower right corner of the rectangle"&@CRLF& _ $SomeName[3]&" - Y coordinate of the lower right corner of the rectangle"&@CRLF& _ $SomeName[4]&" - Handle to the menu bar or popup menu"&@CRLF& _ $SomeName[5]&" - Handle to the submenu"&@CRLF& _ $SomeName[6]&" - True if the menu bar has focus, otherwise False"&@CRLF& _ $SomeName[7]&" - True if the menu item has focus, otherwise False"&@CRLF) EndIf EndIf WEnd Edited February 14, 2012 by Guest Link to comment Share on other sites More sharing options...
Zohar Posted February 14, 2012 Author Share Posted February 14, 2012 Aipion, this works perfect, again! you are something special. Thank you 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