Reputation: 143
I have a small 2160 x 1440 screen, so I use 150% scaling on it in Windows.
Using Cursor.Position
or even GetCursorPos / GetPhysicalCursorPos
I always get the scaled coordinates on my screen (e.g. (2160, 1440) becomes (1440, 960).
I am positive that this is a recent change since I've used Cursor.Position
before on this screen without problems.
How can this behaviour be explained? Why do both GetCursorPos
and GetPhysicalCursorPos
return the same values when they should be different on my screen?
And most importantly, is the only way to get the correct values adjusting what these functions return using the DPI?
Upvotes: 2
Views: 2170
Reputation: 143
For people coming across this issue, I still have no explanation for why there's no distinction between the physical and logical coordinates when retrieving them with GetPhysicalCursorPos
and GetCursorPos
. PhysicalToLogicalPoint
didn't work since it's no longer supported after Windows 8.1.
However, getting all programs to be consistent seems to be possible by making the form dpiAware
in its app.manifest. This essentially makes all coordinates logical, removing the need to compute this using the dpi of the system.
For example, changing the width of the form at runtime changed it by a different amount than when changing it in the editor (1.5 times more). Another example was using Graphics.CopyFromScreen
, which would want the coordinates retrieved by me * 1.5 to work properly. After changing the dpi awareness, this now all works properly.
Upvotes: 4