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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
bl33pingcomputer
Posts: 32
Joined: 29 Dec 2022, 05:36

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

Post by bl33pingcomputer » 29 Jan 2023, 03:31

[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

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

Post by swagfag » 26 Feb 2023, 17:10

its relative to the active window's client area by default, in v2. the docs is wrong

bl33pingcomputer
Posts: 32
Joined: 29 Dec 2022, 05:36

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

Post by bl33pingcomputer » 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.

Imagine a world without Wikipedia... remember to support the things that you want to see stick around and the causes that matter to you.

ntepa
Posts: 404
Joined: 19 Oct 2022, 20:52

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

Post by ntepa » 27 Feb 2023, 05:00

try this in the start of your script:

Code: Select all

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

guest3456
Posts: 3453
Joined: 09 Oct 2013, 10:31

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

Post by guest3456 » 28 Feb 2023, 02:26

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


Post Reply

Return to “Ask for Help (v2)”