Tick Posted April 13, 2021 Share Posted April 13, 2021 (edited) #include <GuiMenu.au3> #include <SendMessage.au3> $hWnd = WinWait("[class:#32768]") ;$hMenu = _GUICtrlMenu_GetMenu($hWnd) ;Not working, next line used $hMenu = _SendMessage($hWnd, 0x01E1) ; MN_GETHMENU - don't know how but it works )) For $i = 0 To _GUICtrlMenu_GetItemCount($hMenu) - 1 MsgBox($MB_SYSTEMMODAL, '', _GUICtrlMenu_GetItemText($hMenu, $i) ,2) ;Shows every item of one-level menu WinMenuSelectItem($hMenu, "", $i); does not click any of the menu items Next Hello dear experts! I can't figure out how to click on the menu item I need. Please help me figure it out. Edited April 14, 2021 by Tick Link to comment Share on other sites More sharing options...
pixelsearch Posted April 14, 2021 Share Posted April 14, 2021 Hi Tick, The only way I found to solve your case is to Send a couple of Key down then Send Enter when you reach the desired context menu item. I really wish another reader could provide a better solution for this, as it would be useful in many cases. Tick 1 Link to comment Share on other sites More sharing options...
LarsJ Posted April 14, 2021 Share Posted April 14, 2021 Shouldn't it be WinMenuSelectItem($hMenu, "", _GUICtrlMenu_GetItemText($hMenu, $i)) And move the last line outside the loop. Tick 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
pixelsearch Posted April 14, 2021 Share Posted April 14, 2021 Hi LarsJ I tried it yesterday with the correct syntax you indicate (3rd param = text of menu item) but it didn't select the item in the context menu (context menu = right click in Scite Window), for example : #include <GuiMenu.au3> #include <SendMessage.au3> $hWnd = WinWait("[class:#32768]") ;$hMenu = _GUICtrlMenu_GetMenu($hWnd) ;Not working, next line used $hMenu = _SendMessage($hWnd, 0x01E1) ; MN_GETHMENU - don't know how but it works )) For $i = 0 To _GUICtrlMenu_GetItemCount($hMenu) - 1 MsgBox($MB_SYSTEMMODAL, '', _GUICtrlMenu_GetItemText($hMenu, $i) ,1) ;Shows every item of one-level menu ; WinMenuSelectItem($hMenu, "", $i); does not click any of the menu items Next $iRet = WinMenuSelectItem($hMenu, "", _GUICtrlMenu_GetItemText($hMenu, 0)) ConsoleWrite($iRet & @CRLF) ; 0 ("menu not found") though the context menu is showing. Sleep(2000) Maybe I didn't get it and you had something else in mind. Could you please post OP's amended script that works on your computer ? Thanks PS: I also tried yesterday what's in this link, but it didn't help (except to retrieve the Items ID's, Texts etc...) Link to comment Share on other sites More sharing options...
Tick Posted April 14, 2021 Author Share Posted April 14, 2021 (edited) Thanks pixelsearch, LarsJ! pixelsearch, I think your method is working in common, but not in my case - there are no hotkeys in my menu and arrows are not working. LarsJ, I've make a try but with negative result( #include <GuiMenu.au3> #include <SendMessage.au3> $hWnd = WinWait("[class:#32768]") $hMenu = _SendMessage($hWnd, 0x01E1) MsgBox($MB_SYSTEMMODAL, '', _GUICtrlMenu_GetItemText($hMenu, 4) ,2) WinMenuSelectItem($hMenu, "", _GUICtrlMenu_GetItemText($hMenu, 4)) Messagebox shows correct menu item, but WinMenuSelectItem does not click. I've use UIAutomate and it works!! #include <UIAutomate.au3> #include <MsgBoxConstants.au3> Opt("WinSearchChildren", 1) Opt("WinTitleMatchMode", 2) ControlClick(WinGetHandle (" MAIN WINDOW"),"","[CLASS:AfxWnd140; INSTANCE:24]","left",1,2,2); - This string calling the menu $hWnd = WinWait("[class:#32768]") $oParent = _UIA_GetElementFromHandle($hWnd) $aElements = _UIA_FindAllElements($oParent, "ControlType", $UIA_MenuItemControlTypeId) _UIA_ElementMouseClick($aElements[4],"left",2,2,2,True); - click desired element ;_UIA_ElementDoDefaultAction($aElements[4]) - do the same thing But I found another problem When screen is locked - I still can not select the menu item. That Controlclick, which calling the menu - works even when the screen is locked, or even when I disconnected from remote desktop. That menu is shows on screen, but they both not working on locked screen This is so bad, because my computer must be unlocked all the time... Maybe you know, what to do to select menu item on locked screen? Maybe I must make the different topic, because original problem was solved?.. Edited April 14, 2021 by Tick Link to comment Share on other sites More sharing options...
Tick Posted April 14, 2021 Author Share Posted April 14, 2021 I've found the manual)) https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F Quote On a locked station any window will never be active (active is only dialog with text "Press Ctrl+Alt+Del"). In Windows locked state applications run hidden (behind that visible dialog) and do not have focus and active status. So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc. Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc. Doing so allows you to interact with an application regardless of whether it is active or not. It's possible to run such a script from scheduler on locked Windows stations. They says that I must use ControlClick or WinmenuSelectItem. But I can't understand, how to controlclick on menu element, and WinmenuSelectItem is not work. _UIA_ElementDoDefaultAction also not working on locked screen(( Link to comment Share on other sites More sharing options...
LarsJ Posted April 14, 2021 Share Posted April 14, 2021 If you are on Windows 10, then I don't think it's possible to automate a menu on a locked PC. For safety reasons. Also, keep in mind that all AutoIt documentation was written before Windows 10 was released. Tick 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Tick Posted April 14, 2021 Author Share Posted April 14, 2021 LarsJ thank you, I understand your message. But I still hope that it is possible to solve this problem somehow )) Anyway Controlclick is working even on locked screen.. So only one step remains - click on the menu item) Link to comment Share on other sites More sharing options...
InnI Posted April 15, 2021 Share Posted April 15, 2021 ; Script opens SciTE pop-up menu and selects "Select All" item #include <GuiMenu.au3> #include <SendMessage.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> $sText = "Select All" ; menu item text Sleep(3333) ; lock desktop manually during this time (Win+L) ControlClick("[Class:SciTEWindow]", "", "Scintilla1", "right") $hWnd = WinWait("[class:#32768]") $hMenu = _SendMessage($hWnd, 0x01E1) ; MN_GETHMENU $iItem = _GUICtrlMenu_FindItem($hMenu, $sText) $aRect = _GUICtrlMenu_GetItemRect($hWnd, $hMenu, $iItem) _MouseLeftClick($hWnd, $aRect[0] + 3, $aRect[1] + 3) Func _MouseLeftClick($hWnd, $X, $Y, $Sleep = 10) Local Const $MK_LBUTTON = 0x0001 _WinAPI_PostMessage($hWnd, $WM_SETCURSOR, $hWnd, _WinAPI_MakeLong($HTCLIENT, $WM_LBUTTONDOWN)) _WinAPI_PostMessage($hWnd, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($X, $Y)) Sleep($Sleep) _WinAPI_PostMessage($hWnd, $WM_SETCURSOR, $hWnd, _WinAPI_MakeLong($HTCLIENT, $WM_LBUTTONUP)) _WinAPI_PostMessage($hWnd, $WM_LBUTTONUP, 0, _WinAPI_MakeLong($X, $Y)) EndFunc pixelsearch and Tick 1 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted April 15, 2021 Share Posted April 15, 2021 (edited) Well done InnI So we can't use MouseClick() as in your simpler 2017 script because of locked screen, right ? Edit: I'm actually reworking a bit your function from 2017. It will allow me to automate a direct mouseclick on a desired context menu item, instead of these "key down + key enter" I got in a couple of scripts. Thanks for your original function, nicely scripted. Edited April 15, 2021 by pixelsearch Tick 1 Link to comment Share on other sites More sharing options...
InnI Posted April 15, 2021 Share Posted April 15, 2021 Yes, right. Link to comment Share on other sites More sharing options...
Nine Posted April 15, 2021 Share Posted April 15, 2021 Is there a specific reason to use your _MouseLeftClick function instead of ControlClick($hWnd, "", "", "left", 1, $X, $Y), which works fine ? Tick and pixelsearch 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted April 15, 2021 Share Posted April 15, 2021 Nine's way is working too. I hope your examples will be useful to OP, who wrote that "Controlclick is working even on locked screen" Link to comment Share on other sites More sharing options...
InnI Posted April 15, 2021 Share Posted April 15, 2021 _MouseLeftClick is an extended ControlClick for left mouse button. Some windows need WM_SETCURSOR message. But if ControlClick works fine, use it. Tick 1 Link to comment Share on other sites More sharing options...
Tick Posted April 15, 2021 Author Share Posted April 15, 2021 Thank you so much InnI - your script is working great in my case!!! But for some reason, on the first try, I just got the menu bar I needed highlighted but not pressed. I just added another command _MouseLeftClick next, and it worked. I think this is some kind of specially introduced difficulties, only this menu in the program for some reason does not allow the cursor to move through the menu items. In any case, I am very grateful, I myself would not have been able to get such a result. Link to comment Share on other sites More sharing options...
InnI Posted April 15, 2021 Share Posted April 15, 2021 20 minutes ago, Tick said: on the first try, I just got the menu bar I needed highlighted but not pressed Try replace to ControlClick ;~ _MouseLeftClick($hWnd, $aRect[0] + 3, $aRect[1] + 3) ControlClick($hWnd, "", "", "left", 1, $aRect[0] + 3, $aRect[1] + 3) Will anything change? Tick 1 Link to comment Share on other sites More sharing options...
jugador Posted April 15, 2021 Share Posted April 15, 2021 @pixelsearch & @Tick #include <GuiMenu.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Example() MsgBox(0, "", 'the end') Func Example() WinWait("[CLASS:Notepad]", "", 10) If Not WinExists("[CLASS:Notepad]") Then Return Local $hWnd = WinGetHandle("[CLASS:Notepad]") ControlFocus($hWnd, "", "Edit1") Send("{APPSKEY}") Local $0_PopUPhwnd = WinGetHandle("[CLASS:#32768]") Local $0_PopUPMenu = _SendMessage($0_PopUPhwnd, 0x01E1) Local $0_FindItem = _GUICtrlMenu_FindItem($0_PopUPMenu, 'Paste') _WinAPI_PostMessage( $hWnd, $WM_COMMAND, _GUICtrlMenu_GetItemID($0_PopUPMenu, $0_FindItem), 0 ) ;_WinAPI_PostMessage($0_PopUPhwnd, $WM_LBUTTONDBLCLK, 0, _WinAPI_MakeLong($x, $Y)) ;~ same as controlclick EndFunc ;==>Example Tick and pixelsearch 1 1 Link to comment Share on other sites More sharing options...
Tick Posted April 16, 2021 Author Share Posted April 16, 2021 3 hours ago, InnI said: Try replace to ControlClick ;~ _MouseLeftClick($hWnd, $aRect[0] + 3, $aRect[1] + 3) ControlClick($hWnd, "", "", "left", 1, $aRect[0] + 3, $aRect[1] + 3) Will anything change? It works too, but also when used twice Link to comment Share on other sites More sharing options...
Tick Posted April 16, 2021 Author Share Posted April 16, 2021 3 hours ago, jugador said: @pixelsearch & @Tick #include <GuiMenu.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Example() MsgBox(0, "", 'the end') Func Example() WinWait("[CLASS:Notepad]", "", 10) If Not WinExists("[CLASS:Notepad]") Then Return Local $hWnd = WinGetHandle("[CLASS:Notepad]") ControlFocus($hWnd, "", "Edit1") Send("{APPSKEY}") Local $0_PopUPhwnd = WinGetHandle("[CLASS:#32768]") Local $0_PopUPMenu = _SendMessage($0_PopUPhwnd, 0x01E1) Local $0_FindItem = _GUICtrlMenu_FindItem($0_PopUPMenu, 'Paste') _WinAPI_PostMessage( $hWnd, $WM_COMMAND, _GUICtrlMenu_GetItemID($0_PopUPMenu, $0_FindItem), 0 ) ;_WinAPI_PostMessage($0_PopUPhwnd, $WM_LBUTTONDBLCLK, 0, _WinAPI_MakeLong($x, $Y)) ;~ same as controlclick EndFunc ;==>Example Thanks a lot! It works! 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