Jump to content
Sign in to follow this  
ch1234

How to show mouse movements with the Au3Recorder tool?

Recommended Posts

ch1234

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.

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
ch1234

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
ch1234

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

Share this post


Link to post
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
Sign in to follow this  

×