Page 1 of 1

[V2.02] MouseMove Doesn't Work As Expected In Dual Monitor Setup

Posted: 29 Jan 2023, 03:31
by bl33pingcomputer
[Moderator's note: Topic moved from Bug Reports.]

Hello gents,

I have a dual monitor setup consisting of a 4K monitor connected to a 1080p laptop via HDMI cable.

The hotkey below only works as expected for the monitor that is set to the main display.

For a window that is not on the main display, it only works as expected when the window is maximized. When the window is not maximized it will move the mouse just outside of the active window's top left corner.

Code: Select all

#SingleInstance Force

`::
{
    MouseMove(0,0) ; WORKS RELATIVE TO ACTIVE WINDOW BY DEFAULT
}
Here are my windows specs:
Edition Windows 11 Home
Version 22H2
Installed on ‎2022-‎11-‎15
OS build 22621.1105
Experience Windows Feature Experience Pack 1000.22638.1000.0

Re: [V2.02] MouseMove Doesn't Work As Expected In Dual Monitor Setup

Posted: 26 Feb 2023, 17:10
by swagfag
its relative to the active window's client area by default, in v2. the docs is wrong

Re: [V2.02] MouseMove Doesn't Work As Expected In Dual Monitor Setup

Posted: 27 Feb 2023, 03:28
by bl33pingcomputer
If that is the case, why does the client area fall outside of the active window on the secondary monitor and not the primary? Shouldn't they be the same (i.e. MouseMove(0,0) should take the mouse position to the top left corner of the active window, regardless of which monitor it is on?

When I enter the exact same coordinates I would like to move the mouse to, using window spy on my secondary (4k) monitor, MouseMove does not move the mouse to those same coordinates.

Re: [V2.02] MouseMove Doesn't Work As Expected In Dual Monitor Setup

Posted: 27 Feb 2023, 05:00
by ntepa
try this in the start of your script:

Code: Select all

; Enable per monitor DPI awareness
DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")

Re: [V2.02] MouseMove Doesn't Work As Expected In Dual Monitor Setup

Posted: 28 Feb 2023, 02:26
by guest3456
bl33pingcomputer wrote:
27 Feb 2023, 03:28
If that is the case, why does the client area fall outside of the active window on the secondary monitor and not the primary? Shouldn't they be the same (i.e. MouseMove(0,0) should take the mouse position to the top left corner of the active window, regardless of which monitor it is on?

When I enter the exact same coordinates I would like to move the mouse to, using window spy on my secondary (4k) monitor, MouseMove does not move the mouse to those same coordinates.
its because you use different scaling %s inside Windows for each of the monitors (right click desktop->display settings)
if you run your script in AHK v1 you will notice the same thing

if you match both monitors to use the same scaling %, then it will work

otherwise use the dllcall in the post above

more info:
viewtopic.php?t=13810