complete milestone 1
This commit is contained in:
@@ -6,8 +6,35 @@
|
||||
|
||||
namespace mosis::test {
|
||||
|
||||
// Callback for EnumWindows to find window by partial title match
|
||||
struct FindWindowData {
|
||||
std::string searchTitle;
|
||||
HWND foundHwnd = nullptr;
|
||||
};
|
||||
|
||||
static BOOL CALLBACK EnumWindowsCallback(HWND hwnd, LPARAM lParam) {
|
||||
auto* data = reinterpret_cast<FindWindowData*>(lParam);
|
||||
|
||||
char title[256] = {0};
|
||||
GetWindowTextA(hwnd, title, sizeof(title));
|
||||
|
||||
// Check if the window title contains our search string
|
||||
if (std::string(title).find(data->searchTitle) != std::string::npos) {
|
||||
data->foundHwnd = hwnd;
|
||||
return FALSE; // Stop enumeration
|
||||
}
|
||||
return TRUE; // Continue enumeration
|
||||
}
|
||||
|
||||
bool WindowController::FindWindow(const std::string& title) {
|
||||
m_hwnd = ::FindWindowA(nullptr, title.c_str());
|
||||
// Use EnumWindows to find window by partial title match
|
||||
// This allows finding "Mosis Designer - home.rml" when searching for "Mosis Designer"
|
||||
FindWindowData data;
|
||||
data.searchTitle = title;
|
||||
|
||||
EnumWindows(EnumWindowsCallback, reinterpret_cast<LPARAM>(&data));
|
||||
|
||||
m_hwnd = data.foundHwnd;
|
||||
if (!m_hwnd) {
|
||||
return false;
|
||||
}
|
||||
@@ -80,24 +107,33 @@ LPARAM WindowController::PhoneToClientLParam(int phoneX, int phoneY) {
|
||||
bool WindowController::SendMouseDown(int phoneX, int phoneY) {
|
||||
if (!m_hwnd) return false;
|
||||
|
||||
// Convert to screen coordinates for SendInput
|
||||
// Convert phone coordinates to client coordinates
|
||||
int clientX = static_cast<int>(phoneX * m_info.scaleX);
|
||||
int clientY = static_cast<int>(phoneY * m_info.scaleY);
|
||||
|
||||
// Get DPI info for debugging
|
||||
UINT dpi = GetDpiForWindow(m_hwnd);
|
||||
|
||||
// Calculate screen coordinates from client position
|
||||
// On DPI-aware systems, Windows APIs return consistent coordinate spaces
|
||||
int screenX = m_info.clientX + clientX;
|
||||
int screenY = m_info.clientY + clientY;
|
||||
|
||||
// Use SendInput for proper GLFW compatibility
|
||||
// First move the cursor to the position
|
||||
SetCursorPos(screenX, screenY);
|
||||
// Ensure window is foreground before clicking
|
||||
SetForegroundWindow(m_hwnd);
|
||||
Sleep(10); // Small delay
|
||||
|
||||
// Use SendInput for GLFW compatibility
|
||||
SetCursorPos(screenX, screenY);
|
||||
Sleep(10); // Small delay for cursor move
|
||||
|
||||
// Send mouse down via SendInput
|
||||
INPUT input = {};
|
||||
input.type = INPUT_MOUSE;
|
||||
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
||||
SendInput(1, &input, sizeof(INPUT));
|
||||
|
||||
std::cout << "MouseDown at phone(" << phoneX << "," << phoneY << ") -> screen("
|
||||
<< screenX << "," << screenY << ")" << std::endl;
|
||||
<< screenX << "," << screenY << ") dpi=" << dpi << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -105,12 +141,15 @@ bool WindowController::SendMouseDown(int phoneX, int phoneY) {
|
||||
bool WindowController::SendMouseUp(int phoneX, int phoneY) {
|
||||
if (!m_hwnd) return false;
|
||||
|
||||
// Send mouse up via SendInput
|
||||
Sleep(10); // Small delay before release
|
||||
|
||||
INPUT input = {};
|
||||
input.type = INPUT_MOUSE;
|
||||
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
||||
SendInput(1, &input, sizeof(INPUT));
|
||||
|
||||
Sleep(10); // Small delay after release
|
||||
|
||||
std::cout << "MouseUp at phone(" << phoneX << "," << phoneY << ")" << std::endl;
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user