Jump to content

ControlClick clicking the correct position


inna
 Share

Go to solution Solved by Jfish,

Recommended Posts

Hi, this is my code:

Run('notepad.exe')
WinWaitActive("Notepad", '', '1')
Local $x = 428 ; position is 'some'
Local $y = 142 ; position is 'some'
Local $i = 1
While $i <= 5
        Send('This is some text and i is $i' & $i)
        ControlClick('[Class:Notepad]', '', '', 'left', '2', $x, $y)
        $i = $i + 1
        Send('{ENTER}')
WEnd
MouseMove($x, $y)

Function ControlClick() does not click at (428, 142), but it clicks at the end of line which is this output when I run:

Quote

This is some text and i is $i1
This is some text and i is $i2
This is some text and i is $i3
This is some text and i is $i4
This is some text and i is $i5

I expect this:

Quote

Writes 'This is some text and i is $i1', then clicks on the bold word, hits Enter button, now the new text should be:

This is 

This is some text and i is $i2 text and i is $i1

Did I miss anything or am I doing wrong?

Link to comment
Share on other sites

Oh I posted topic early:(

I mean when the ControlClick() works, it double clicks on some, but when it tries to write the next loop, it goes to the next line.

Up to selecting the position, it is working fine; but the continue does not work.

Link to comment
Share on other sites

11 hours ago, Jfish said:

Not sure I follow you 100% but it goes to the next line because you are sending the enter key to Notepad

Yes, but before hitting enter, I'm double clicking on a position (a word), so it should remove that word and goes to the next line.

You can test it in your editor: write something, double click on a word, then hit enter to see how it goes.

Link to comment
Share on other sites

  • Solution

Double clicking the word in Notepad only selects it. Then when you send enter you are basically erasing that word and replacing it with a carriage return which moves everything after that to the next line (while preserving everything before it on the line which had the selected word). EDIT: and it does remove that word when it is replaced with the carriage return if that is the problem you are trying to solve. Change the value of x to 100 and run the code. Here it is with a sleep so you can see what is happening: 

Run('notepad.exe')
WinWaitActive("Notepad", '', '1')
Local $x = 100; position is 'some'
Local $y = 142 ; position is 'some'
Local $i = 1
While $i <= 2
        Send('This is some text and i is $i' & $i)
        ControlClick('[Class:Notepad]', '', '', 'left', '2', $x, $y)
        sleep(1000)
        $i = $i + 1
        Send('{ENTER}')
WEnd
MouseMove($x, $y)

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

1 minute ago, Jfish said:

Double clicking the word in Notepad only selects it. Then when you send enter you are basically erasing that word and replacing it with a carriage return which moves everything after that to the next line (while preserving everything before it on the line which had the selected word).

Yes, that is correct, I am trying to achieve this which should happen but does not, but I fail.

Link to comment
Share on other sites

11 minutes ago, Jfish said:

try the code in my edited post, yours works that way too but you are highlighting / selecting the very last text on the line instead of "some" because your X value is off

For me it still highlight the last word, presses enter and continue.

Also MouseMove goes to SOME but double clicking only clicks $i1 and $i2:(

Link to comment
Share on other sites

when you run the code I posted you should see this as output:

This is 
This is 
text and i is $i2text and i is $i1

It is selecting "some" and replacing it with a carriage return.  Of course, you can also solve this problem by editing the text before you send it to Notepad,

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

33 minutes ago, Jfish said:

Double clicking the word in Notepad only selects it. Then when you send enter you are basically erasing that word and replacing it with a carriage return which moves everything after that to the next line (while preserving everything before it on the line which had the selected word). EDIT: and it does remove that word when it is replaced with the carriage return if that is the problem you are trying to solve. Change the value of x to 100 and run the code. Here it is with a sleep so you can see what is happening: 

Run('notepad.exe')
WinWaitActive("Notepad", '', '1')
Local $x = 100; position is 'some'
Local $y = 142 ; position is 'some'
Local $i = 1
While $i <= 2
        Send('This is some text and i is $i' & $i)
        ControlClick('[Class:Notepad]', '', '', 'left', '2', $x, $y)
        sleep(1000)
        $i = $i + 1
        Send('{ENTER}')
WEnd
MouseMove($x, $y)

 

I don't know why, but your code works as I wanted.

But there are something I do not understand:

When ControlClick clicks on x and y, it selects SOME.

But MouseMove goes to another position which is outside of Notepad at all.

I think this difference is my issue. As I figured out, MouseMove goes to absolute position but ControlClick's default x and y are the center. Should I use x and y apps to find the center of my monitor and then see where SOME is?

I think if I run the script in different environments with different resolutions and different sizes of Notepad, I'll get different answers. Am I rught?

Link to comment
Share on other sites

10 minutes ago, inna said:

I don't know why, but your code works as I wanted.

 

Because I adjusted X.  We are not using MouseMove which you have referenced a couple of times in the code.  We are using parameters as part of the ControlClick function that tell the code where to click within the targeted control. X is one of those parameters. Not sure what you are seeing about the mouse moving outside the control, I don't see that. If your code has MouseMove then that could cause that issue because it is not relative to the control per se, rather to the screen.

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

On 10/28/2022 at 3:42 PM, Jfish said:

Because I adjusted X.  We are not using MouseMove which you have referenced a couple of times in the code.  We are using parameters as part of the ControlClick function that tell the code where to click within the targeted control. X is one of those parameters. Not sure what you are seeing about the mouse moving outside the control, I don't see that. If your code has MouseMove then that could cause that issue because it is not relative to the control per se, rather to the screen.

Thanks, then I should calculate different x and y for different monitors?

My screen is 1920*1080, but suppose another screen is 1024*724. Then I think from center of each screen going 100px up and 142px left would be different.

Am I right?

As I had another topic, please advise how to find a word of button for ControlClick.

For ControlClick I think I should find its class name and id and other specs, but for word I'm not sure.

, please 

Link to comment
Share on other sites

52 minutes ago, inna said:

Thanks, then I should calculate different x and y for different monitors?

 

Didn't it work on your machine / monitor when you ran the code?  You said "I don't know why, but your code works as I wanted." Did you have to adjust anything to make it work?  I already answered the other thread you posted (please keep posts/threads separate) you should try the approach I linked.  

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

2 hours ago, Jfish said:

Didn't it work on your machine / monitor when you ran the code?

Yes it worked fine.

2 hours ago, Jfish said:

You said "I don't know why, but your code works as I wanted." Did you have to adjust anything to make it work?

No, I did not change anything. When I changed x and y to somewhere where MouseClick clicks on, the ControlClick did not work. But Copying exactly your code worked in my screen too.

2 hours ago, Jfish said:

I already answered the other thread you posted (please keep posts/threads separate) you should try the approach I linked. 

Yes I know I should keep them separated. I just noticed if there's another way to find the proper x and y for ControlClick.

Do you help me how did find x and y coordination are 100 and 142? In a bigger screen does it work too? Because the x and y center of another sized screen is different with me (1920 x 1080) and yours (probably 1920 x 1080).

Link to comment
Share on other sites

You should test on another machine but as previously mentioned, the coordinates for the controlclick function are relative to the control as compared to mousemove that is relative to the screen. We seem to be just repeating the same info at this point so I am going to wish you the best with the project. 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

5 minutes ago, Jfish said:

the coordinates for the controlclick function are relative to the control

Sorry for asking a lot, I read the docs but I didn't understand this part. This function's coordinates are relative to control? In this case there's only one Notepad window (of course there's a Windows window behind).

Please see the attached image.

In this picture there are two supposed points: the red dot which is the center of notepad window, and the black dot which is the center of my screen.

By relative, you mean relative to the red or black dot?

Did I understand your states right?

example.png

Link to comment
Share on other sites

Now I'm seeing what's in Summary tab of AutoIt v3 Window Info mean.

I see a ControlClick coords that you wrote the  code and where it came from, and where is x and y of my mouse there.

I think this topic could be closed because I got the answer by your code and investigating more to see how your code works.

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

  • Recently Browsing   0 members

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