#include "ui/base/win/event_creation_utils.h"
#include <windows.h>
#include <winuser.h>
#include <algorithm>
#include "ui/gfx/geometry/point.h"
namespace ui {
bool SendMouseEvent(const gfx::Point& point, int flags) {
INPUT input = {INPUT_MOUSE};
const int screen_left = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
const int screen_top = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
const int screen_width = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
const int screen_height = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
int screen_x =
std::clamp(point.x(), screen_left, screen_left + screen_width - 1);
int screen_y =
std::clamp(point.y(), screen_top, screen_top + screen_height - 1);
static constexpr double kNormalizedScreenSize = 65536.0;
input.mi.dx = static_cast<LONG>(
std::max(1.0, std::ceil((screen_x - screen_left) *
(kNormalizedScreenSize / screen_width))));
input.mi.dy = static_cast<LONG>(
std::max(1.0, std::ceil((screen_y - screen_top) *
(kNormalizedScreenSize / screen_height))));
input.mi.dwFlags = static_cast<DWORD>(flags | MOUSEEVENTF_ABSOLUTE);
return ::SendInput(1, &input, sizeof(input)) == 1;
}
}