Fixis Posted February 13, 2012 Share Posted February 13, 2012 Hello everyone, I've tried to move the mouse cursor to a button before clicking it, although the click worked the mouse moved to a wrong place. I use this code: $positionArray = ControlGetPos ("Visual Prolog 7", "", "[TEXT:&New Project]") MouseMove($positionArray[0] , $positionArray[1], 70) ControlClick("Visual Prolog 7", "", "[TEXT:&New Project]") I tried to use this option before the code: Opt("MouseCoordMode", 0) But it doesn't move the mouse over the button, I tried to do it with 1 and 2 insted of 0, it moves the mouse to a different place but still not on the button. If anyone can help me, I will be grateful Link to comment Share on other sites More sharing options...
Bert Posted February 13, 2012 Share Posted February 13, 2012 (edited) you don't need to do a mouse move when using controlclick. The point of ControlClick is you can interact with controls without using the mouse. Edited February 13, 2012 by MPH The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Fixis Posted February 13, 2012 Author Share Posted February 13, 2012 No, I know that , however I want the person on the computer to see how the mouse cursor moves, on which button exactly it clicks and so on Link to comment Share on other sites More sharing options...
guinness Posted February 13, 2012 Share Posted February 13, 2012 ControlGetPos and MouseMove. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Fixis Posted February 13, 2012 Author Share Posted February 13, 2012 ControlGetPos and MouseMove.I'm using them, what is wrong with my code? Link to comment Share on other sites More sharing options...
Bert Posted February 13, 2012 Share Posted February 13, 2012 You have to specify the position of the control you want, not the position of your mouse. Get the location of the control using AutoInfoTool. Then do a mouse move to that location. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Fixis Posted February 13, 2012 Author Share Posted February 13, 2012 I used the finder tool to point at the button. I get Position: 229, 500. When I make MouseMove(229 , 500, 70) The mouse moves up and left from the button. I have to do MouseMove(229 + 40 , 500 + 50, 70) To be on the button. It is some sort of solution, but I have no idea why should I increase X with 40 and Y with 50. I have a different situation when I want to move to a Cancel button in a different form, this time I have to increase X with 20 and Y with 20 Is there a way for me to know why should I increase X and Y of the Control's Position and with what numbers? Link to comment Share on other sites More sharing options...
Bert Posted February 13, 2012 Share Posted February 13, 2012 OK, I see the problem. You need to have this in the beginning of your script: Opt("MouseCoordMode", 2) This sets your mouse coords to the active window. Make sure you have the AutoItWindowInfo tool set the same way when you get the coords. Skysnake 1 The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
fett8802 Posted February 13, 2012 Share Posted February 13, 2012 (edited) I actually wrote a function for this years ago and have used it in many of my hardware/software testing programs. This will do exactly what you want: ; #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 = "10", $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 MouseClick($iButton,$aPos[0] + ($aPos[2]/2) + $iXpos, $aPos[1] + ($aPos[3]/2) + $iYpos, $iClicks, $iSpeed) ;Move the mouse and click on the given control Opt("MouseCoordMode",$iOriginal) ;Change the MouseCoordMode back to the original EndFunc ;==>_ControlMouseClick There ya go. -Fett Edited February 13, 2012 by fett8802 [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] Link to comment Share on other sites More sharing options...
Fixis Posted February 13, 2012 Author Share Posted February 13, 2012 Thanks so much for helping me Fett, it really works the right way now Link to comment Share on other sites More sharing options...
guinness Posted February 13, 2012 Share Posted February 13, 2012 fett8802, You should post this in the AutoItWrappers thread. Fixis, I totally missed your code from the first post sorry. In the future place AutoIt code in the [autoit][/autoit] tags as it makes the code stand out a little more. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
guinness Posted February 13, 2012 Share Posted February 13, 2012 fett8802, You can shorten your code because Opt returns the previous value $iOriginal = Opt("MouseCoordMode", 2) $aPos = ControlGetPos($iTitle .... UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
fett8802 Posted February 13, 2012 Share Posted February 13, 2012 Thanks so much for helping me Fett, it really works the right way nowYou're very welcome! I'm glad it worked for you!fett8802,You should post this in the AutoItWrappers thread. Thanks for the feedback, I'll do that!-Fett [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] Link to comment Share on other sites More sharing options...
fett8802 Posted February 13, 2012 Share Posted February 13, 2012 fett8802, You can shorten your code because Opt returns the previous value $iOriginal = Opt("MouseCoordMode", 2) $aPos = ControlGetPos($iTitle .... Oh! Excellent! Not sure why I didn't see that in the help file. That will help shave off a bunch of code from my UDFs. - Fett [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] 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