Dream4soul Posted May 21, 2018 Posted May 21, 2018 Dears, Please help me. I need a script that will navigate through a menu. For that, I use the follow key press sequence. {ALT down}{f down}{f up}{s down}{s up}{ALT up}. On the notepad all works fine but on my application not. For sending key press I use function like Send, ControlSend, _WinAPI_Keybd_Event. When I use actual key press on my application it works, but no in autoit script. Please advise what to do. forum.au3
Earthshine Posted May 21, 2018 Posted May 21, 2018 (edited) you want people to guess at what you are automating? what good does that do? Depending on what you are automating makes a world of difference how you approach it Edited May 21, 2018 by Earthshine My resources are limited. You must ask the right questions
Moderators JLogan3o13 Posted May 21, 2018 Moderators Posted May 21, 2018 (edited) @Dream4soul while the response you got was way more harsh for someone new to the forum than it needed to be, there is some validity there. You state that in notepad this is working fine, but in your application it does not - yet you don't tell us the application. Nor do you give any idea what "doesn't work" means. We cannot assist in troubleshooting when you provide so little information. Please let us know what application you're trying to automate, what exactly the steps you're carrying out in your script are intended to accomplish, and what isn't working (is it throwing errors, just not pressing the buttons, etc.?). Please help us help you Edited May 21, 2018 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Dream4soul Posted May 21, 2018 Author Posted May 21, 2018 Application that I what to manage it is specific application used in airlines companies from SITA called Leason. Access to this application is limited. This is desktop application with menu and terminal area. In this menu I have File->Open. To open this dialog, I can use keyboard. And it is WORKS from keyboard. But when I use autoit nothing happens. First guess was that script is wrong. I make tests on Notepad, all works fine. I try different commands to sent key pressing, all of them work in Notepad but not in my application. My question is, how it is possible that from keyboard it works but from script it doesn’t work? Script attached. P.S Menu in this application is accessible. I can reedit with _GUICtrlMenu_GetMenu, _GUICtrlMenu_GetItemText, _GUICtrlMenu_GetItemSubMenu. I try WinMenuSelectItem but it is not working to. ☹((((((
Earthshine Posted May 21, 2018 Posted May 21, 2018 (edited) Depending on what this app is authored in will determine if or how to proceed. What does the information tool return about the elements you want to automate? Information tool can be brought up from the editor under the tools menu and you can click on the things that you want to automate and it will return data about that control. If you can do that please post the controls that you care about and we’ll see what the best options would be For instance, modern WPF applications are not automatable by plain auto IT And other methods are necessary Edited May 21, 2018 by Earthshine My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 AutoIT window info return 3 handlers first for main window and menu, second for toolbox an third for terminal screen. Screenshot and window summery attached. window+menu.txt toolbar.txt terminal.txt
Earthshine Posted May 22, 2018 Posted May 22, 2018 ahhhh, terminal emulation. have to see what we can do about that. my best bet is @junkew will have something to say about this, but I could be all wrong. I will check out what I can find. My resources are limited. You must ask the right questions
Earthshine Posted May 22, 2018 Posted May 22, 2018 (edited) I did find out that it has a command line, and that would be so much easier to deal with if you could do that instead. Anyway, it looks like your Terminal Emulator is authored in Visual Basic 6 and uses some custom controls (AfxOleControl421) but that control may or may not respond to plain AutoIT script. We may have to go down the IUIAutomation thread to automate that GUI which can be a challenge in it's own. I know with our old VB6 stuff and custom controls that is the only way to do it. FAQ 31 section dealing with IUIAuotomation should get you started. Oh, can you post your code that you have tried? Edited May 22, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted May 22, 2018 Posted May 22, 2018 no. that is your notepad test. the real thing would be better. also, just use the code tags <> to post your code. Place Code Here My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 expandcollapse popup#include <WinAPISys.au3> #include <MsgBoxConstants.au3> #include <GuiMenu.au3> #include <AutoItConstants.au3> Opt ("TrayIconDebug", 1) Example() Func Example() ; Retrieve the handle of the Notepad window using the classname of Notepad. Local $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator") ;Local $hWnd = WinGetHandle("Untitled - Notepad") If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.") Exit EndIf ; Display the handle of the Notepad window. ;MsgBox($MB_SYSTEMMODAL, "", $hWnd) WinActivate($hWnd) SendKeepActive($hWnd) WinWaitActive($hWnd) Sleep(500) ; _WinAPI_Keybd_Event(0x12, 0) ;ControlSend ($hWnd, "", "", "{ALTDOWN}") Send("{ALT down}") ;SendInput("!f") Sleep(500) ;ControlSend ($hWnd, "", "", "f") Send("{f down}") ; _WinAPI_Keybd_Event(0x46, 0) Sleep(500) Send("{f up}") ; _WinAPI_Keybd_Event(0x46, 2) Sleep(500) Send("{s down}") Sleep(500) Send("{s up}") ;ControlSend ($hWnd, "", "", "{ALTUP}") Send("{ALT up}") Sleep(500) ;_WinAPI_Keybd_Event(0x12, 2) EndFunc ;==>Example
Earthshine Posted May 22, 2018 Posted May 22, 2018 (edited) For that menu, your finder did not find anything, which I find very strange. Could you re-check that? Also, regarding your script: You can't use no arguments to ControlClick or ControlSend, at least give it a title and the proper control ID else you don't know what you are talking to. It also appears like your regular sends don't work either. You must use the AutoIT Info Tool to get the data and use that data in your calls to ControlSend and such. Edited May 22, 2018 by Earthshine My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 Local $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator") ;Local $hWnd = WinGetHandle("Untitled - Notepad") If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.") Exit EndIf ; Display the handle of the Notepad window. MsgBox($MB_SYSTEMMODAL, "", $hWnd) WinActivate($hWnd) SendKeepActive($hWnd) WinWaitActive($hWnd) Sleep(500) Opt("WinTitleMatchMode", 4) ;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then ;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." ) EndIf All 3 controls return "Debug: Click failed." :((((
Earthshine Posted May 22, 2018 Posted May 22, 2018 (edited) Quote Opt("WinTitleMatchMode", 3) ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) try that. we should also be able to get to that Menu it has as well. Please capture the data for that. If you can't capture it, it is some whacky menu control. Edited May 22, 2018 by Earthshine My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 Opt("WinTitleMatchMode", 4) ;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then ;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then ;if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then ;if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]") then ; Debug: Successfull click if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",20,20) then ;Debug: Click failed. MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." ) EndIf "Debug: Click failed.". But if I remove the coordinate x/y Debug: Successfull click. I comment in the code. Earthshine 1
Earthshine Posted May 22, 2018 Posted May 22, 2018 Similarly the controlSend should also work if you wanted to send key commands My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 I found ControlSend has different syntax if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]","left",1,100,100) then this return Successfull click. I will try to open a dialog menu. Earthshine 1
Earthshine Posted May 22, 2018 Posted May 22, 2018 Coolness. Let us know. My resources are limited. You must ask the right questions
Dream4soul Posted May 22, 2018 Author Posted May 22, 2018 expandcollapse popupLocal $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator") ;Local $hWnd = WinGetHandle("Untitled - Notepad") If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.") Exit EndIf ; Display the handle of the Notepad window. ; MsgBox($MB_SYSTEMMODAL, "", $hWnd) WinActivate($hWnd) SendKeepActive($hWnd) WinWaitActive($hWnd) Sleep(500) Opt("WinTitleMatchMode", 4) ;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then ;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then ;if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then ;if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]","left",1,298,266) then ; Debug: Successfull click if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "","left",1,138,238) then ; Debug: Successfull click MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." ) EndIf if ControlSend($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]","","{ALTDOWN}") then ; Debug: Successfull click MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull ALTDOWN.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: ALTDOWN failed." ) EndIf Sleep(500) if ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "f") then MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull f.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: f failed." ) EndIf Sleep(500) if ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "y") then MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull y.") Else MsgBox($MB_SYSTEMMODAL, "","Debug: y failed." ) EndIf Sleep(500) ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "{ALTUP}") All steps return successful code but nothing happen :(( only if I use physical keyboard:((
Earthshine Posted May 22, 2018 Posted May 22, 2018 Are you running in administrator mode? Does your script require admin mode it probably should My resources are limited. You must ask the right questions
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