Jump to content

How to show mouse movements with the Au3Recorder tool?


Recommended Posts

I'm trying to automate an install to speed it up (it's currently very manual and takes ages to do) so I want to use AutoIt to help in this respect.

I used the Au3Recorder tool to generate my MouseClicks and WinWaitActivates but I can't get it to visibly move the mouse to the relevant points that the script clicks. It's not super important that this feature is implemented but I'd like to be able to incorporate it if possible.

My code is:

#region ---Au3Recorder generated code Start (v3.3.7.0) ---

#region --- Internal functions Au3Recorder Start ---
Func Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
EndFunc

Func WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc

AU3RecordSetup()
#endregion --- Internal functions Au3Recorder End ---

WinWaitActivate("Window A","Welcome")
;MouseMove(748,687) ;Absolute Coords
MouseMove(341,415) ;Relative to Active Window Coords
Sleep(500)
MouseClick("left",341,415,1)

WinWaitActivate("Window A","To continue with")
;MouseMove(432,648) ;Absolute Coords
MouseMove(258,380) ;Relative to Active Window Coords
Sleep(500)
MouseClick("left",258,380,1)

;MouseMove(742,691) ;Absolute Coords
MouseMove(356,419) ;Relative to Active Window Coords
Sleep(500)
MouseClick("left",356,419,1)

WinWaitActivate("Window A","Install")
;MouseMove(742,691) ;Absolute Coords
MouseMove(356,419) ;Relative to Active Window Coords
Sleep(500)
MouseClick("left",356,419,1)

WinWaitActivate("Window A","Successful.")
;MouseMove(639,568) ;Absolute Coords
MouseMove(211,178) ;Relative to Active Window Coords
Sleep(500)
MouseClick("left",211,178,1)

#endregion --- Au3Recorder generated code End ---

I added in the MouseMove commands but it just doesn't want to work with the rest of the code. I've also tried alternating between absolute coordinates and coordinates relative to the active window and that still doesn't work.

Can anybody spot any glaring errors? I'm using Windows Server 2008 R2.

Link to comment
Share on other sites

Use handles...much more reliable than mouseclicks...you will also be able to run the scripts while not logged in that way, since you won't need a visible gui:

controlgethandle

controlclick

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Use handles...much more reliable than mouseclicks...you will also be able to run the scripts while not logged in that way, since you won't need a visible gui:

controlgethandle

controlclick

Ok, thanks for the advice. I've tried that and it does seem much nicer to use. I'm trying to integrate this into a C# App and I can't get the Handles working. I'm using the basic AutoIt example and it won't run. Are there any glaring omissions in my code?

AutoItX3Lib.AutoItX3 autoit = new AutoItX3Lib.AutoItX3();
          
string handle = autoit.WinGetHandle("[CLASS:Notepad]", "this one");
// MessageBox.Show(handle, "");
autoit.WinActivate(handle);
autoit.ControlSend(handle, "", "Edit1", " test test test ");

I've registered the dll etc and other AutoIt commands are working but I don't understand what's wrong here. I want the notepad window to be brought to the front (ie be the active window) and then send the text to it. If I enable the MessageBox, it returns the correct hex code for the handle.

This is the AutoIt code I've adapted:

; Identify the Notepad window that contains the text "this one" and get a handle to it
; Get the handle of a notepad window that contains "this one"
Local $handle = WinGetHandle("[CLASS:Notepad]", "this one")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
WinActivate($handle)
    ; Send some text directly to this window's edit control
    ControlSend($handle, "", "Edit1", " AbCdE ")
EndIf
Link to comment
Share on other sites

Which program do you try to install? Most of the programs have a silent install command line switch.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Which program do you try to install? Most of the programs have a silent install command line switch.

It's not a particular individual program, it's a collection of a lot of small drivers/programs etc. I know about the /s command but I need it to be visible on the screen hence the get handles etc

EDIT: I can get it WinActivate and ControlSend working in C# if I remove 'handle' and type in the string "Untitled - Notepad". I don't really understand why that's the case as the COM help file says that it returns a string on success so surely it shouldn't matter whether it's the handle variable or the hardcoded "Untitled - Notepad" string?

I've checked with the Window Info Tool and the program is capturing the correct handle.

Edited by ch1234
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...