Jump to content
Sign in to follow this  
tentacole

Change ControlClick coordinates - While loop

Recommended Posts

Afternoon!

This is my first post, so I apologize if this is in the wrong place. 

I've created a while loop to click in a certain area of an application, and have the y axis change at the end of each loop. My loop continues to click at x:27, x:10, even though the $y is adding 15 at the end of each loop. I did a Send($x) and Send($y) into a Notepad to see if the $y had changed after each loop, and the 15 was being added to $y each loop. (If this makes sense)

 

I'm unsure where I'm going wrong, and would be extremely grateful if someone can point me in the correct direction to fix this. 

Local $rDirectory = "H:\oDemandProject\fList.txt"
    Local $rLine = _FileCountLines($rDirectory)
    Local $x = 27
    Local $y = 10  
    
   While $rline > 0
       WinActivate("OnDemand", "-> 1")
       WinWaitActive("OnDemand", "-> 1")
       ControlClick("OnDemand", "", "[CLASS:AfxFrameOrView120u; INSTANCE:1]", "left", 4, $x, $y)
       $y += 15
      $rLine -= 1
   WEnd

 

Share this post


Link to post
Share on other sites

The coordinates in ControlClick are the coordinates within the bounds of the control you're clicking on. What's the control you need to click and how large is it that you need to click it so far apart each time?

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
3 hours ago, BrewManNH said:

The coordinates in ControlClick are the coordinates within the bounds of the control you're clicking on. What's the control you need to click and how large is it that you need to click it so far apart each time?

 

It's a line of text that I plan to copy and paste into a notepad file. 

For example:

Click x: 27 y: 10, copy, paste into notepad

Click x: 27 y: 25, copy, paste into notepad

Click x: 27 y: 40,copy, paste into notepad

 

But the selects x: 27 y: 10 throughout the entire script.

Share this post


Link to post
Share on other sites

What is the control that you're clicking on, what is the size of the control, and why do you need to copy and paste anything into Notepad? Reread what I wrote above, then answer the questions.  What program are you manipulating, and why do you think that it's clicking in the same place every time?

There's obviously more of this script than what you posted, I can't answer your questions, until I see more of your script. Is this portion inside a function? What you posted should work fine, although I still don't know what you're trying to click on, and as explained above, the coordinates in ControlClick are the coordinates inside the bounds of a control, and not the screen or window.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
11 hours ago, BrewManNH said:

What is the control that you're clicking on, what is the size of the control, and why do you need to copy and paste anything into Notepad? Reread what I wrote above, then answer the questions.  What program are you manipulating, and why do you think that it's clicking in the same place every time?

There's obviously more of this script than what you posted, I can't answer your questions, until I see more of your script. Is this portion inside a function? What you posted should work fine, although I still don't know what you're trying to click on, and as explained above, the coordinates in ControlClick are the coordinates inside the bounds of a control, and not the screen or window.

>>>> Window <<<<
Title:  OnDemand
Class:  Afx:00400000:b:00010005:00000006:0CF9158D
Position:   -8, -8
Size:   1936, 1176
Style:  0x15CF0000
ExStyle:    0x00000300
Handle: 0x00770CDA

>>>> Control <<<<
Class:  AfxFrameOrView120u
Instance:   1
ClassnameNN:    AfxFrameOrView120u1
Name:   
Advanced (Class):   [CLASS:AfxFrameOrView120u; INSTANCE:1]
ID: 59648
Text:   
Position:   10, 57
Size:   1879, 503
ControlClick Coords:    27, 10
Style:  0x50000000
ExStyle:    0x00000200
Handle: 0x01B20888

>>>> Mouse <<<<
Position:   37, 67
Cursor ID:  0
Color:  0x00FF00

Yes, there is more to this code. The program I'm using is a program that stores .pdf letters. The script is to automate a search of a range of dates, search for a specific string within those date ranges, and then copy an ID that each letter has and paste it into a notepad. This is the information that is provided to me through Autoit v3 Window Info. I am attempting to double click on a line of text within this Control. After it clicks on the first line, I'm attempting to double click on the next line of text, which those ControlClick Coordinates are 27, 25. My assumption to the problem is that variable type for $y changes after adding 15 to $y each loop, but I'm unsure.

Share this post


Link to post
Share on other sites

I figured out the problem. There are two windows within the program, when you have the first selected, the control instance is 1 and the second window's control is instance 2... But when you have the second window selected, that control is instance 1, and the first window's control is instance 2. The WinActivate("OnDemand", "-> 1") is not selecting the correct window. 

Share this post


Link to post
Share on other sites

Have you tried just parsing the file directly instead of clicking all over to try and get the text you want?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Try to manage your windows like that it will be more easy and efficiant : 

Local $rDirectory = "H:\oDemandProject\fList.txt"
    Local $rLine = _FileCountLines($rDirectory)
    Local $x = 27
    Local $y = 10  
    
$MyWindow = WinGetTitle ("OnDemand", "" )

While $rline > 0
   If Not WinActive( $MyWindow , "" ) Then
   MsbBox( 0 , "Care!" , "Window Not Active" )
     Do
       If Not WinActive( $MyWindow , "" ) Then WinActivate("OnDemand", "-> 1")
       Sleep ( 200 ) 
     Until WinActive( $MyWindow , "" )
   EndIf
       ControlClick( $MyWindow , "" , "[CLASS:AfxFrameOrView120u; INSTANCE:1]" , "left" , 4 , $x , $y )
       $y += 15
       $rLine -= 1
WEnd

Like that if the windows is changing you wont be able to do anything on it. And you will know it.

 

About this line : 

ControlClick( $MyWindow , "" , "[CLASS:AfxFrameOrView120u; INSTANCE:1]" , "left" , 4 , $x , $y )

If you are managing the click like a MouseClick Why not use mouseClick ?

The only difference is the #SendMessage Or #Message sent to the application.  Do you need to do anything on minimized window ? 

WinActivate is saying me nop you dont. I am correct ? If yes just use mouseclick. With WinMove... It will be 50X more easy.

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
On 11/22/2018 at 1:34 PM, BrewManNH said:

Have you tried just parsing the file directly instead of clicking all over to try and get the text you want?

That was my original plan. I had planned on using the command FileReadLine on the .txt file I'm using - then ctrl + f for that string, but was unsure how to proceed from there. Only thought I had was to move the mouse to the highlighted text then double click it.

Share this post


Link to post
Share on other sites

Is there specific text in the text file you're looking for? If so, read the whole file, search for the text you need, then copy whatever it is from where that text is to another file. This way it's all done in memory and there's no need for Notepad, ControlClick or any other less reliable methods. 

If you can post a sample of the type of text file you're dealing with, minus anything identifiable or confidential, then let us know what it is you're looking for in that file and what you're looking to get into the second file, we can narrow down the parameters with something that might work better for you. 

I'm sure one of our RegEx gurus could easily parse a file with one or 2 lines of RegEx knowing the genius of them. :)

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Similar Content

    • By TheDcoder
      Hello, it has been a long time since I have posted here
      I am working on an AutoIt project where I need to enable to user to interactively choose any point or coordinate on the screen... something like a big overlay where the user can click anywhere on the screen to select that point. @UEZ's screenshot tool may have something similar to what I need:
      I just checked the source code for the tool and I see that the Mark_Area function has a part in selecting the area to screenshot, I tried to figure out how it works but it is simply too complex and long...
      So I was wondering if there were any examples of interactively selecting points on a screen? Maybe an UDF that I can just use in my script to make the whole thing a matter of adding few lines
      Thank you for the replies in advance!
    • By AutoPM
      #RequireAdmin AutoItSetOption('MouseCoordMode', 0) If WinExists("newtitle") Then ControlClick('newtitle', '', 'Button1') EndIf a Simple script to click Button on GUI with title "newtitle". this script is working fine on my laptop on [windows 10, windows 7]
      but on a different laptop. script is not clicking this button, is there any alternative to control click then please tell. don't want to use mouseclick 
       
      Thank you
    • By Yirrlaar
      #Include <WinAPI.au3> local $ClassName = _WinAPI_GetClassName(WinGetHandle(WinGetTitle("[ACTIVE]"))) ControlClick(WinGetTitle("[ACTIVE]"), "", "[CLASS:"&$ClassName&"; INSTANCE:1]", "primary") When I am running this script it just gives me a ConsoleWrite output of "0x001D04A8"
      When using "AutoIT v3 Window Info" all the info I need for the ControlClick is there and displayed perfectly as if I typed it in normally.
      Upon click the button it should be clicking it, I see the following inn the console window:
      If I replace the $ClassName with the actual ClassName of "WindowsForms10.BUTTON.app.0.3296db7_r14_ad1" it works just fine, any ideas???
    • By Tats
      Hi everyone,
      I have a problem with ControlClick function. It doesn't work no matter how I tried all the possible combination of the parameters.
      Below is the scripts of possible parameter combination:
      ;ControlClick("title","text","controlID ","button","clicks","x","y") ;title= Title, Class, Handle ;controlID= Class, ClassNN, Instance ;Title here is empty when I check it with AutoIt Info ControlClick("", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("", "", "[INSTANCE:18]", "left", "1", "230","890") ;Title here is the Class of the window ControlClick("[ScreenKeyboard::SKFrame]", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("[ScreenKeyboard::SKFrame]", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("[ScreenKeyboard::SKFrame]", "", "[INSTANCE:18]", "left", "1", "230","890") ;Title here is the Handle of the window ControlClick("[0x000907A0]", "", "[ScreenKeyboard::Button18]", "left", "1", "230","890") ControlClick("[0x000907A0]", "", "[CLASS:ScreenKeyboard::Button; INSTANCE:18]", "left", "1", "230","890") ControlClick("[0x000907A0]", "", "[INSTANCE:18]", "left", "1", "230","890") Am I coding it correctly?
      Thanks
    • By MaximusCZ
      Hello, and apologies if this have been discussed before, but I googled and couldnt find anything relevant.
      I have a problem where I try to send a control clink into to a window. 
      Part of window I try to send clicks to looks like this . The black border is showing when I mouse over it Au3Info, I get following information:

      I am testing its interaction with code

      The result I get is that it makes control clicks trough first line, opens and closes menus, as expected.
      When It gets to second line, it does not click a single icon. I can tell that coords are correct as the dropdown menus (No view active) gets focused(altough not rolled out). Same behaviour happens if roughly 40<y<60, so I know I am hitting good height. You can look at how it behaves here: output.webm 
      Dropdown 1 focuses at around 8 sec mark, and 13 sec mark it changes to second dropdown, defocusing first one, seemingly not registering any clinks inbetween.
       
      Have you ever encountered similar behaviour? I need to click the Key button, first on second line, with controlclick (or any other way not hijacking the mouse). I cant trigger that button by keyboard and There is no other control having control over it.
      Help
       
×
×
  • Create New...