When using the win32api from pywin, I am getting incorrect values for the cursor position. My screen\'s resolution is 1920x1080, but when I use GetCursorPos() I have (0,0) i
You are subject to DPI virtualization. Your application has not declared itself aware of high DPI and you have a font scaling of 125%.
If you want to avoid DPI virtualization either add the high DPI aware option to the application manifest or call either SetProcessDPIAware
or SetProcessDPIAwareness
.
You can set the awareness level like this:
import ctypes
awareness = ctypes.c_int()
ctypes.windll.shcore.SetProcessDpiAwareness(2)
The awareness levels are defined as follows:
typedef enum _PROCESS_DPI_AWARENESS {
PROCESS_DPI_UNAWARE = 0,
/* DPI unaware. This app does not scale for DPI changes and is
always assumed to have a scale factor of 100% (96 DPI). It
will be automatically scaled by the system on any other DPI
setting. */
PROCESS_SYSTEM_DPI_AWARE = 1,
/* System DPI aware. This app does not scale for DPI changes.
It will query for the DPI once and use that value for the
lifetime of the app. If the DPI changes, the app will not
adjust to the new DPI value. It will be automatically scaled
up or down by the system when the DPI changes from the system
value. */
PROCESS_PER_MONITOR_DPI_AWARE = 2
/* Per monitor DPI aware. This app checks for the DPI when it is
created and adjusts the scale factor whenever the DPI changes.
These applications are not automatically scaled by the system. */
} PROCESS_DPI_AWARENESS;
Check this answer: https://stackoverflow.com/a/44422362/8537759