移动鼠标指针到目标窗口的客户区坐标
| 469 | |
| 470 | // 移动鼠标指针到目标窗口的客户区坐标 |
| 471 | bool Utils::moveMouseToClientArea(HWND hwnd, int x, int y) { |
| 472 | if (hwnd == nullptr || !IsWindow(hwnd)) { |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | QMutexLocker locker(&m_locker); |
| 477 | |
| 478 | // 将客户区坐标转换为屏幕坐标 |
| 479 | POINT clientPoint = { x, y }; |
| 480 | if (!ClientToScreen(hwnd, &clientPoint)) { |
| 481 | qWarning() << "Failed to convert client area coordinates to screen coordinates."; |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | // 使用 SetCursorPos 将鼠标移动到目标位置(屏幕坐标) |
| 486 | if (!SetCursorPos(clientPoint.x, clientPoint.y)) { |
| 487 | qWarning() << "Failed to move mouse to target position."; |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | qDebug() << "Mouse moved to client area coordinates: (" |
| 492 | << x << ", " << y << ")"; |
| 493 | |
| 494 | return true; |
| 495 | } |
| 496 | |
| 497 | bool Utils::clickWindowClient(HWND hwnd) { |
| 498 | if(hwnd == nullptr || !IsWindow(hwnd)){ |
nothing calls this directly
no outgoing calls
no test coverage detected