Sign in to follow this  
Followers 0
AussieTimmeh

Using ControlClick and a known reference

5 posts in this topic

Hi all,

I have used ControlClick successfully many times before when I want to click the control I am referencing. However I am having trouble getting my head around clicking buttons that I can't reference directly.

For a program I use at work, I need to click on a series of buttons whose locations always remain the same but whose instance numbers change depending on how many assets there are that day. However, one button is always a constant instance number.

Now, using MouseMove I can get the mouse to move to each of these buttons by referencing the known constant instance.

;Find the known button position
$buttonpos = ControlGetPos("", "", "[CLASS:QWidget; INSTANCE:22]")  
;Move the mouse to button 1
MouseMove($buttonpos[0] + 20, $buttonpos[1] -50)
Sleep(2000)
;Move the mouse to button 2
MouseMove($buttonpos[0] + 40, $buttonpos[1] -50)
Sleep(2000)

Now, I can use MouseClick to click these buttons but it actually moves the mouse, which I am trying to avoid. I know I can sample the mouse position and return the mouse fairly quickly, but it seems messy when I think I should be able to do what I want with ControlClick, which does not move the mouse. However, this code does not work:

;Click button 1
ControlClick("", "", "[CLASS:QWidget; INSTANCE:22]", "left", 1, 20, -50)    
Sleep(2000)
;Click button 1
ControlClick("", "", "[CLASS:QWidget; INSTANCE:22]", "left", 1, 40, -50)    
Sleep(2000)

Can anyone enlighten me as to why this does not work? Is there any debug or way I can set Windows to see where the ControlClick is actually clicking on the screen? Is there a better way to do this without moving the mouse?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use the autoitwindow info tool on the button, and output the summary back to us...it's best to use some stale identifier, like the ID.

You might get by with using the text instead.

You can't include click coords inside of controlclick that are outside the bounds of the control...it ends up not doing anything.  It won't click relative to the control, it sends at the control, but with invalid data, so the control is not clicked.

Example...I have a window with 2 buttons.  The x-start of the second button is 190 pixels right of the start of the first button...this will NOT perform a click on the first button (outside the width of the button), or the second (since not relative clicks)

WinActivate("Login")
ControlFocus("Login","",15212)
ControlClick("Login","",15212,"left",1,200,10)
Edited by jdelaney

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

What about scanning the list of available controls to find which ones are located at the desired positions? See >this post for a possible starting point.

Share this post


Link to post
Share on other sites

What about scanning the list of available controls to find which ones are located at the desired positions? See >this post for a possible starting point.

 I should put that in my sig.  It's a good debugger.


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

Thanks for the info and ideas guys, I'll see what I can come up with.

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  
Followers 0