Jump to content

Change ControlClick coordinates - While loop


 Share

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

 

Link to comment
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

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
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. 

Link to comment
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

Link to comment
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 : ( 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

 

Link to comment
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.

Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...