diff --git a/keypress_simulator/packages/keypress_simulator_windows/windows/keypress_simulator_windows_plugin.cpp b/keypress_simulator/packages/keypress_simulator_windows/windows/keypress_simulator_windows_plugin.cpp index b827601..681990e 100644 --- a/keypress_simulator/packages/keypress_simulator_windows/windows/keypress_simulator_windows_plugin.cpp +++ b/keypress_simulator/packages/keypress_simulator_windows/windows/keypress_simulator_windows_plugin.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -126,8 +127,18 @@ void KeypressSimulatorWindowsPlugin::SimulateMouseClick( y = std::get(it_y->second); } + // Get the monitor containing the target point and its DPI + const POINT target_point = {static_cast(x), static_cast(y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + // Scale the coordinates according to the DPI scaling + int scaled_x = static_cast(x * scale_factor); + int scaled_y = static_cast(y * scale_factor); + // Move the mouse to the specified coordinates - SetCursorPos(static_cast(x), static_cast(y)); + SetCursorPos(scaled_x, scaled_y); // Prepare input for mouse down and up INPUT input = {0};