Jump to content

Do some programs not work with AutoIt?


Recommended Posts

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

@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 by TheXman
Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

  • 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.
Link to comment
Share on other sites

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

  • 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

 

 

 

 

Link to comment
Share on other sites

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

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

  • 2 years later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...