2 or more monitors and XY positions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

2 or more monitors and XY positions

Post by foxdanger » 10 Jun 2021, 20:41

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?
Rohwedder
Posts: 7558
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: 2 or more monitors and XY positions

Post by Rohwedder » 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
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: 2 or more monitors and XY positions

Post by foxdanger » 11 Jun 2021, 13:07

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?
Rohwedder
Posts: 7558
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: 2 or more monitors and XY positions

Post by Rohwedder » 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.
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: 2 or more monitors and XY positions

Post by foxdanger » 15 Jun 2021, 17:11

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?
User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: 2 or more monitors and XY positions

Post by boiler » 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.
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: 2 or more monitors and XY positions

Post by foxdanger » 15 Jun 2021, 18:12

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
User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: 2 or more monitors and XY positions

Post by boiler » 15 Jun 2021, 18:39

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.
Post Reply

Return to “Ask for Help (v1)”