azcn2503 Posted April 13, 2016 Share Posted April 13, 2016 (edited) Hi, I am trying to create an automation script that will realistically mimic a users input suitable for recording in a repeatable manner. I am able to use the MouseMove command to hover an icon on the desktop, double click it, and open the software. I searched these forums for a reliable way to use MouseMove to move to a control on the new window and found this article: I have modified the code to look like this so I can see the movement of the mouse: Func _ControlMouseClick($iTitle, $iText, $iControl, $iButton = "left", $iClicks = "1", $iSpeed = "30", $iXpos = "", $iYpos = "") $iOriginal = Opt("MouseCoordMode") ;Get the current MouseCoordMode Opt("MouseCoordMode",2) ;Change the MouseCoordMode to relative coords $aPos = ControlGetPos($iTitle, $iText, $iControl) ;Get the position of the given control ConsoleWrite("Control position: " & $aPos[0] & "x" & $aPos[1]) MouseMove($aPos[0] + ($aPos[2]/2) + $iXpos, $aPos[1] + ($aPos[3]/2) + $iYpos, $iSpeed) $mPos = MouseGetPos() ConsoleWrite("Cursor position: " & $mPos[0] & "x" & $mPos[1]) MouseClick($iButton, Default, Default, $iClicks, $iSpeed) ;Move the mouse and click on the given control Opt("MouseCoordMode",$iOriginal) ;Change the MouseCoordMode back to the original EndFunc ;==>_ControlMouseClick Now, when I try to call this function using the following code: _ControlMouseClick($installerTitle, "", "[CLASS:Button; INSTANCE:2]") I get the following written to the console: Quote Control position: 362x489Cursor position: -249x-75 And the mouse has not visibly moved across the screen at all. It is still hovering the icon on the desktop. Here is the full code I have: ; #FUNCTION# ==================================================================================================================== ; Name...........: _ControlMouseClick ; Description ...: Use the mouse to move to a control and click it ; Syntax.........: _ControlMouseClick($iTitle, $iText, $iControl [, $iButton = "left" [, $iClicks = "1" [, $iSpeed = "10" [, $iXpos = "" [, $iYpos = "" ]]]]] ) ; Parameters ....: $iTitle - The title of the window containing the control ; $iText - Some text from the window containing the control. Can enter no text be using "" ; $iControl - The Control ID of the control to click ; $iButton - [optional] The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary". Default is "left" ; $iClicks - [optional] The number of times to click the mouse. Default is 1. ; $iSpeed - [optional] The speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10. ; $iXpos - [optional] The x position to click within the control. Default is center. ; $iYpos - [optional] The y position to click within the control. Default is center. ; Author ........: Kris Mills <fett8802 at gmail dot com> ; UserCallTip....: _ControlMouseClick ( "title", "text", controlID [, button [, clicks [, speed [, x [, y ]]]]] ) Use the mouse to move to a control and click it.(required: #include <KrisUDF.au3>) ; =============================================================================================================================== Func _ControlMouseClick($iTitle, $iText, $iControl, $iButton = "left", $iClicks = "1", $iSpeed = "30", $iXpos = "", $iYpos = "") $iOriginal = Opt("MouseCoordMode") ;Get the current MouseCoordMode Opt("MouseCoordMode",2) ;Change the MouseCoordMode to relative coords $aPos = ControlGetPos($iTitle, $iText, $iControl) ;Get the position of the given control ConsoleWrite("Control position: " & $aPos[0] & "x" & $aPos[1]) MouseMove($aPos[0] + ($aPos[2]/2) + $iXpos, $aPos[1] + ($aPos[3]/2) + $iYpos, $iSpeed) $mPos = MouseGetPos() ConsoleWrite("Cursor position: " & $mPos[0] & "x" & $mPos[1]) MouseClick($iButton, Default, Default, $iClicks, $iSpeed) ;Move the mouse and click on the given control Opt("MouseCoordMode",$iOriginal) ;Change the MouseCoordMode back to the original EndFunc ;==>_ControlMouseClick MouseMove(110, 110, 30) MouseClick("", Default, Default, 2) $installerTitle = "Setup" WinWait($installerTitle) WinActivate($installerTitle) _ControlMouseClick($installerTitle, "", "[CLASS:Button; INSTANCE:2]") Any thoughts on getting this to work so that the cursor moves smoothly over the control I am specifying? Edited April 13, 2016 by azcn2503 Changed title Link to comment Share on other sites More sharing options...
azcn2503 Posted April 13, 2016 Author Share Posted April 13, 2016 (edited) Update: It seems that any MouseMove command after the installer opens is ignored. I tested this by doing the following: MouseMove(110, 110, 30) ; Move to the item on the desktop MouseClick("", Default, Default, 2) ; Double click it MouseMove(0, 0, 100) MouseMove(200, 200, 100) MouseMove(400, 400, 100) The mouse will stop moving before it reaches 0,0 because the installer opens. Any MouseMove command after this point does nothing. Any thoughts? Edited April 13, 2016 by azcn2503 Link to comment Share on other sites More sharing options...
azcn2503 Posted April 13, 2016 Author Share Posted April 13, 2016 Update: it was my bad. The installer was running as admin (though I didn't realise this as UAC was disabled) and I was running the script from SciTE editor as a standard user. Once I ran SciTE as admin it worked without any issue. 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