Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

ControlGetPos and MouseMove.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

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?

Posted (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 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]
Posted

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:

  Reveal hidden contents

Updated: 22/04/2018

Posted

fett8802,

You can shorten your code because Opt returns the previous value

$iOriginal = Opt("MouseCoordMode", 2)
$aPos = ControlGetPos($iTitle ....

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 2/13/2012 at 4:33 PM, 'Fixis said:

Thanks so much for helping me Fett, it really works the right way now

You're very welcome! I'm glad it worked for you!

  On 2/13/2012 at 4:42 PM, 'guinness said:

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]
Posted

  On 2/13/2012 at 4:50 PM, 'guinness said:

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]

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
  • Recently Browsing   0 members

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