brew Posted June 11, 2018 Share Posted June 11, 2018 Hi, I am an experienced programmer, but have only done a couple of AutoIt scripts a couple of years ago. I am now trying to write a script to automate some activities within a couple of astronomy programs. Everything works fine with a VB.NET program I wrote, Paint, and Notepad. However, I cannot get AutoIt to interact with another program Canopus (used to create asteroid light curves). This program was written by another astronomer; I can't imagine it has any special security or anything to prevent AutoIt from working. I do not know what he used to create it. When I activate the main window it will come to the front if it is behind other windows. The window is recognized and an hWnd is returned. However, if it is minimized, it will not restore it using WinSetState($hWnd, "", @SW_RESTORE) MouseMove, MouseClick, ControlSend, and Send have no effect on the Activated window. My first task is to bring up a window; it can be done by sending ^+s or by clicking a menu selection in the menubar. However, I can't get any Send characters or mouse operations to occur. Here is a stripped down test script. When it runs, the mouse never moves and the dialog never comes up. Maybe I am missing something:( #include <AutoItConstants.au3> Opt("WinTitleMatchMode", 2) ; match window titles by substring Opt("SendKeyDownDelay", 50) Opt("MouseCoordMode", 0) ; mouse by window coord func VerifyCanopusReady() Local $hWnd = WinWait("MPO Canopus", "", 10) WinSetState($hWnd, "", @SW_RESTORE) if (WinActivate($hWnd)) then ; try clicking the Menu Bar MouseMove(132, 41) MouseClick($MOUSE_CLICK_LEFT) ; no effect Sleep(500) Send("^+s") ; try key shortcut - no effect Sleep(500) ; EndIf EndFunc VerifyCanopusReady() Link to comment Share on other sites More sharing options...
TheXman Posted June 11, 2018 Share Posted June 11, 2018 (edited) @brew Just looking at the snippet that you posted, how do you know if you have a valid $hWnd? You didn't test it to make sure. If it is 0, then of course the restore would fail, the mouse would never move, and the dialog would never appear. You could try the code below just to make sure. #include <Constants.au3> Opt("WinTitleMatchMode", 2) ; match window titles by substring Opt("SendKeyDownDelay", 50) Opt("MouseCoordMode", 0) ; mouse by window coord VerifyCanopusReady() Func VerifyCanopusReady() Local $hWnd = WinWait("MPO Canopus", "", 10) If $hWnd = 0 Then Exit MsgBox($MB_TOPMOST+$MB_ICONERROR, "ERROR", "Unable to get window handle") WinSetState($hWnd, "", @SW_RESTORE) if (WinActivate($hWnd)) then ; try clicking the Menu Bar MouseMove(132, 41) MouseClick($MOUSE_CLICK_LEFT) ; no effect Sleep(500) Send("^+s") ; try key shortcut - no effect Sleep(500) ; EndIf EndFunc Edited June 11, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
brew Posted June 11, 2018 Author Share Posted June 11, 2018 To make the snippet shorter, I took out the hWnd check. Yes, there was a non-zero hex value there. Note that the WinActivate succeeds, the window comes to the front. The window is accessible. I just can't do anything with it. Link to comment Share on other sites More sharing options...
TheXman Posted June 11, 2018 Share Posted June 11, 2018 Sorry, not sure what the problem could be unless the app is hooking into mouse and keyboard window messages and not properly passing them on. I've been using AutoIt for over 10 years and haven't come across an application/process that I couldn't automate. I guess those apps exist and maybe you've come across one. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
AutoBert Posted June 11, 2018 Share Posted June 11, 2018 5 hours ago, brew said: Do some programs not work with AutoIt? as you see: yes! Link to comment Share on other sites More sharing options...
Earthshine Posted June 11, 2018 Share Posted June 11, 2018 (edited) many many programs don't work with autoit, or at least standard autoit (you might need to use other udf libraries) Edited June 11, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
junkew Posted June 11, 2018 Share Posted June 11, 2018 Check faq31 and use simplespy or inspect.exe to give more details on the objects you can identify by highlightning. aa2zz6 1 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...
brew Posted June 11, 2018 Author Share Posted June 11, 2018 I don't know about simplespy or inspect.exe. I do run AutoIt v3 Window Info to find control / window / mouse information. It reports various controls and windows as expected, although any attempt at using those control names has no result. So, I can "read" from the application but not "write" to it. The various controls are names like TPanel1, TBitBtn3 (a button), TOvcDbPictureField12 (a text field), Edit1 (another text field) in case this is a clue for what the program is written in and what the problem is. Thanks for looking at this:) Link to comment Share on other sites More sharing options...
junkew Posted June 11, 2018 Share Posted June 11, 2018 please read faq31 https://www.autoitscript.com/wiki/FAQ#How_can_I_control_.28click.2C_edit_etc.29_an_external_.28html.29_application.3F that will tell you where to find simplespy. If you are an experienced programmer on windows you should now that you can find inspect.exe in windows sdk It looks a delphi programming language it was made with not sure if you can easily recognize the controls besides falling back to bitmap recognition. If you can read from the application you should be able to move mouse and click at element to set focus location and after that send keys to the control. simplespy is part of what I made in UIA Wrappers which recognizes more then AutoIt out of the box with the disadvantage that its (apparently for many) less userfriendly in coding then the AutoIt functions. 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...
brew Posted June 11, 2018 Author Share Posted June 11, 2018 I did read the FAQ. It seemed to be a) concerned mostly with automating browsers, which I am not doing, and c) discussing other spy options. It seems that I do not particularly need other spy options, the AutoIt tool reports control name, mouse positions, etc just fine. I agree with your third point - it seems like I should be able to move mouse, etc. That is the problem... I will look at the bitmap approach, see if I can make that work. Link to comment Share on other sites More sharing options...
junkew Posted June 11, 2018 Share Posted June 11, 2018 you are missing the UIA answer in faq 31. Its talking with UIA about many different types and classes of controls certainly not only beeing webbased. The spy tools simplespy and inspect.exe sometimes reveal more information then you can get with Au3Inf. It could be that UIA gives you more details / depth of hierarchy. In general its worth the try. If nothing is revealed then some commercial spytools reveal more. For delphi it could be worth to check with testcomplete trial version (although if it works after that you have to buy a license). Maybe another solution could be before doing bitmaps is to click percentagewise more stable and easier then bitmaps certainly if your executable has stable GUI testpercentagemove("50%","50%") func testpercentagemove($x,$y) if stringinstr($x,"%") Then $realX=stringreplace($x,"%","") * (@DesktopWidth / 100) $realy=stringreplace($y,"%","") * (@DesktopHeight / 100) mousemove($realX ,$realy) EndIf EndFunc 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...
brew Posted June 12, 2018 Author Share Posted June 12, 2018 Well, this example certainly works - it just moves around the screen. It has no interaction with the target program. I see that the bitmap stuff is just to location positions on the program window. I already know the coordinates and control names from the AutoIt spy program, so this doesn't help anything. Here is another simple test. It works on every window I try it on: Alt-c moves the mouse twice toward the upper corner of the window. However, there is no response on the program I want to use. The mouse never moves Opt("WinTitleMatchMode", 2) ; match window titles by substring Opt("MouseCoordMode", 0) ; mouse by window coord HotKeySet("!c", "testmove") Func testmove() MouseMove(100, 100) Sleep(500) MouseMove(20, 10) Sleep(500) EndFunc while (1) Sleep(10) WEnd It sounds like this just isn't going to work. I will start looking for another tool. Link to comment Share on other sites More sharing options...
brew Posted June 12, 2018 Author Share Posted June 12, 2018 Aha - I found the answer. It turns out the program I am trying to work with runs as Administrator. It will not work if run with standard privileges. It turns out any program (i.e., Paint) will not respond to script mouse/key actions if they are run as administrator. Per the manual, the #RequireAdmin statement allows the script to run with administrator privileges, and everything works. Link to comment Share on other sites More sharing options...
Jont Posted January 28, 2021 Share Posted January 28, 2021 I have multiple unrelated applications that behave in this way only *some* of the time (i.e. sometimes MouseClick and Send work with them, sometimes not). In some cases at least they are definitely not elevated, and I can't see any reason why sometimes they allow interaction and sometimes they don't. Running my script elevated (either by executing it in an elevated context or by using #RequireAdmin) doesn't make any difference - AutoIt still fails to MouseMove, MouseClick or Send while the application is activated. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 28, 2021 Developers Share Posted January 28, 2021 We know, but what exactly does your post contribute to this old thread? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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