Modify

Opened 2 years ago

Last modified 8 weeks ago

#3884 assigned Bug

MouseCoordMode, cursor moving and DPI unawareness

Reported by: vadcx Owned by: Jon
Milestone: Component: AutoIt
Version: 3.3.16.0 Severity: None
Keywords: mouse, move, coordinate, click, position, scale, dpi Cc:

Description

MouseMove documentation (and others) refer to MouseCoordMode which says:

MouseCoordMode: Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:
0 = relative coords to the active window
1 = (default) absolute screen coordinates
2 = relative coords to the client area of the active window

So the simple way to acquire absolute screen coordinates when needed:

  1. Take a screenshot of the entire screen
  2. Write down coordinates by navigating the picture

Let's say the mouse must be moved to 100,100 absolute.

MouseMove(100, 100)

If you didn't touch Windows' DPI settings (100%) then the cursor will move to 100,100. However if you set the DPI to 125% then the cursor moves to 125,125 and so on. Either the documentation must be clarified or the behaviour changed.

But it gets worse. Windows now has per-display DPI scaling. What is a script supposed to do in that case? This seems to be described in this AHK-related thread that seems to have the exact same problem as Au3.

Attachments (2)

MouseMove at default awareness isnt correct.png (62.0 KB) - added by vadcx 2 years ago.
The cursor position was set at default awareness but 125% scaling. The cursor was slightly incorrectly drawn by the screenshot tool but you get the idea
mouse-move-dpi-awareness.au3 (1.1 KB) - added by vadcx 2 years ago.
DPI awareness AutoIt mouse move test script

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 years ago by Jpm

Hi,
I don't know why you conclue they move to 125,125
The following script prove that the Mouse pos return by MouseGetPos() is 100, 100
perhaps a little mistake due to the speed implementation

MouseMove(110, 200, 0)
Local $aPos = MouseGetPos()
ConsoleWrite("Mouse Pos=(" & $aPos[0] & ', ' & $aPos[1] & ')' & @CRLF)

_MouseMove(120, 300)
Local $aPos_ = MouseGetPos()
ConsoleWrite("_Mouse Pos=(" & $aPos_[0] & ', ' & $aPos_[1] & ')' & @CRLF)

Func _MouseMove($x, $y)
	Local $aCall = DllCall("User32.dll", "Bool", "SetCursorPos", "int", $x, "int", $y)
	Return $aCall[0]
EndFunc


Changed 2 years ago by vadcx

The cursor position was set at default awareness but 125% scaling. The cursor was slightly incorrectly drawn by the screenshot tool but you get the idea

Changed 2 years ago by vadcx

DPI awareness AutoIt mouse move test script

comment:2 Changed 2 years ago by vadcx

The Win32 API lies to you. :) Just for completeness, I forgot to specify the OS: Windows 10 (1-2mo old) at 125% DPI.

I've attached a screenshot and a test script now. The script is supposed to move the cursor to the center of a 1080p screen (assuming you've only 1 display enabled) and show what Windows reports to you BEFORE/AFTER you change own DPI awareness.

From the screenshot:

Default awareness:
GetDpiForSystem: 96 its a lie
MousePos: 961,541
its a lie and, AutoIt, it's off by a pixel


System-wide DPI Awareness set:
GetDpiForSystem: 120 correct, 96*1.25 = 120
MousePos: 1201,676
correct, this is what I see as a user

I used these APIs: GetDpiForSystem, SetProcessDpiAwareness - I wanted to use the per-thread DPI setting, but it required getting hold of DPI_AWARENESS_CONTEXT - I don't know how to do it in Au3 or if its possible at all to acquire (it's a predefined HANDLE in windef.h)

comment:3 Changed 2 years ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

Fix sent to Jon
using SetCursorPos() solve the issue

comment:4 Changed 2 years ago by Jpm

  • Component changed from Documentation to AutoIt

comment:5 Changed 8 weeks ago by Jpm

  • Owner changed from Jpm to Jon

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as assigned The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.