mouse coordinates are different Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

mouse coordinates are different

06 May 2021, 10:51

Hello, everyone. First post here and I'm really enjoying AHK. I have a script that uses mouse position to move the mouse to a certain position and then left click. The problem I'm finding is that the position it needs to move to varies slightly between identical computers. Is there a way to make this more reliable without having to make small adjustments to the mouse position. I got the mouse position using the Window Spy and I used the default coordinates. Below is the code snippet. The original code that worked fine on my laptop had Click, 393, 405. Thanks for the help!

Code: Select all

SendInput {Enter}
Sleep 200
SendInput {Tab 1}
SendInput 9003
Sleep 500
SendInput {Tab 3}
Sleep 200
Send {Click,493,456}
Sleep 200
Send {Click,297,85}
Sleep 200
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: mouse coordinates are different

06 May 2021, 11:23

There could be other ways to find your target more reliably using ControlClick or other information about the target or the target window. It depends on the specific details.
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

Re: mouse coordinates are different

06 May 2021, 11:34

mikeyww wrote:
06 May 2021, 11:23
There could be other ways to find your target more reliably using ControlClick or other information about the target or the target window. It depends on the specific details.
I'm clicking on a chevron that opens another window. In the second window I have to click on elipse (...). This opens other windows where I enter data. I will read about ControlClick. I'm trying to be thick headed but what more detail could I provide that would help? I'm more than willing to provide it.
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: mouse coordinates are different

06 May 2021, 11:44

Running Window Spy will show you control names. If you have just two computers, then an alternative is providing two sets of coordinates. Another option is an ImageSearch. In some cases, a formula might work, such as working with a percentage of the window width. If it is in a Web browser, then there are other methods with JavaScript, Chrome.ahk, etc.; searching the forum will show examples. An ImageSearch could probably find a chevron easily-- though it's also possible that the two computers have two different displays of this chevron. You would need to test.
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

Re: mouse coordinates are different

06 May 2021, 12:01

mikeyww wrote:
06 May 2021, 11:44
Running Window Spy will show you control names. If you have just two computers, then an alternative is providing two sets of coordinates. Another option is an ImageSearch. In some cases, a formula might work, such as working with a percentage of the window width. If it is in a Web browser, then there are other methods with JavaScript, Chrome.ahk, etc.; searching the forum will show examples. An ImageSearch could probably find a chevron easily-- though it's also possible that the two computers have two different displays of this chevron. You would need to test.
Thank you again for the reply. The application I'm working in is Windows based. We will have multiple (>50) computers using it once I feel like I've done my due diligence testing it. We all use pretty much the same laptop and some OS, Win10. Most of the script contains tabs and down arrow key strokes. These 2 objects will not get the focus so I can use a keystroke. I have to use the mouse coordinates and the left click.

I will look at your suggestions of an Image search and the percentage of window width. Thanks again for helping.
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

Re: mouse coordinates are different

06 May 2021, 12:15

The second chevron is what I'm trying to click that I'm having difficulty with the mouse coordinates. Anything you see that may help?
image.png
image.png (50.83 KiB) Viewed 1449 times
image.png
image.png (15.96 KiB) Viewed 1449 times
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: mouse coordinates are different

06 May 2021, 12:26

If the chevron can accept a keyboard focus, as the screenshot suggests, then you might be able to use a Send sequence to navigate to it, and then activate it. One trick I have used in some programs is to use a +{Tab} sequence from a starting point, to navigate backwards until the target control is reached.

Others on the forum here might have additional suggestions.
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

Re: mouse coordinates are different

06 May 2021, 14:00

I found that the test laptop that is having the mouse coordinate issues has slightly different Active Window Position than what I posted above, which is from my machine.

Test machine
x:577 y:230 w:766 h:580
client x:0 y:0 w:750 h:541

My machine has:
x:577 y:257 w:766 h:525
client x:0 y:0 w:750 h:486

any ideas on how to compensate so the mouse click can be consistent. The chevron looks like it gets the focus when you mouse over it, but you can't tab to it.
Attachments
image.png
image.png (63.54 KiB) Viewed 1424 times
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: mouse coordinates are different  Topic is solved

06 May 2021, 15:39

Since the windows have a different height, you could try making the dimensions uniform (WinMove) to see whether that resolves the issue with differing coordinates. I do not have additional ideas for you beyond that.
jadams0173
Posts: 8
Joined: 06 May 2021, 09:35

Re: mouse coordinates are different

07 May 2021, 08:10

mikeyww wrote:
06 May 2021, 15:39
Since the windows have a different height, you could try making the dimensions uniform (WinMove) to see whether that resolves the issue with differing coordinates. I do not have additional ideas for you beyond that.
Thank you for all your help! it is much appreciated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 439 guests