Page 1 of 1

2 or more monitors and XY positions

Posted: 10 Jun 2021, 20:41
by foxdanger
So, I have a simple software where the person can click on a button and it waits you to position your mouse on a point of the screen and than hit enter.

After you hit enter, it saves the mouse position on a variable.

After that I can use that position stored on the variable to send the mouse there when I want.

The problem is:

This works with one monitor.

If the person is using two or more monitors, and move the mouse for a second monitor and hit enter, the position saved just don't work.

How I can make the mouse move and find the mouse position on a second monitor?

Re: 2 or more monitors and XY positions

Posted: 11 Jun 2021, 01:39
by Rohwedder
Hallo,
https://www.autohotkey.com/docs/commands/CoordMode.htm#Remarks
If this command (CoordMode) is not used, all commands except those documented otherwise (e.g. WinMove and InputBox) use coordinates that are relative to the active window.
Use:

Code: Select all

CoordMode, Mouse, Screen

Re: 2 or more monitors and XY positions

Posted: 11 Jun 2021, 13:07
by foxdanger
Rohwedder wrote:
11 Jun 2021, 01:39
Hallo,
https://www.autohotkey.com/docs/commands/CoordMode.htm#Remarks
If this command (CoordMode) is not used, all commands except those documented otherwise (e.g. WinMove and InputBox) use coordinates that are relative to the active window.
Use:

Code: Select all

CoordMode, Mouse, Screen
First of all, thx for your answer.

So, every mouse move or when I saving the mouse position on the screen, I need to use coordmode, is that?

Re: 2 or more monitors and XY positions

Posted: 12 Jun 2021, 01:11
by Rohwedder
Only if the current coordinate mode does not meet your current needs!
Why try to change something that already fits?
in my Auto-execute section I set all CoordMode, except TargetType Menu, to Screen and change it only if necessary.

Re: 2 or more monitors and XY positions

Posted: 15 Jun 2021, 17:11
by foxdanger
Rohwedder wrote:
12 Jun 2021, 01:11
Only if the current coordinate mode does not meet your current needs!
Why try to change something that already fits?
in my Auto-execute section I set all CoordMode, except TargetType Menu, to Screen and change it only if necessary.
So there's a way to setup the aplication to coordmode and everything will be in coordmode screen forever?

Re: 2 or more monitors and XY positions

Posted: 15 Jun 2021, 17:36
by boiler
Once you execute a CoordMode statement, it remains in effect until you change it. That’s why Rohwedder said he just sets it in the auto-execute section (at the top of the script). It’s then good for everything that follows as long as he doesn’t change it somewhere.

Re: 2 or more monitors and XY positions

Posted: 15 Jun 2021, 18:12
by foxdanger
boiler wrote:
15 Jun 2021, 17:36
Once you execute a CoordMode statement, it remains in effect until you change it. That’s why Rohwedder said he just sets it in the auto-execute section (at the top of the script). It’s then good for everything that follows as long as he doesn’t change it somewhere.
Thx one more time for your help.

So if I do this at the begin of the code. If I do not touch in coordMode again in any place of the code, it will be always refered to the screen, and if it is using two monitors, he will get the right position?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen

Re: 2 or more monitors and XY positions

Posted: 15 Jun 2021, 18:39
by boiler
I wouldn’t guarantee that it will work with no problems because people have reported issues with MouseMove over multiple monitors, and even the documentation implies that there are sometimes issues depending on the setup. See this thread, for example.