|
@@ -1245,3 +1245,267 @@ namespace GAssist
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+namespace GameAssist {
|
|
|
+ void SetGameForeground(HWND hWnd)
|
|
|
+ {
|
|
|
+ if (!IsWindow(hWnd))
|
|
|
+ return;
|
|
|
+
|
|
|
+ ::ShowWindow(hWnd, SW_SHOWNORMAL);
|
|
|
+ ::SetForegroundWindow(hWnd); // 窗口前置才能单击成功;
|
|
|
+ }
|
|
|
+
|
|
|
+ BOOL GamePos2Screen(HWND hWnd, POINT& pt, bool bOffset)
|
|
|
+ {
|
|
|
+ if (!::IsWindow(hWnd)) return FALSE;
|
|
|
+ if (bOffset) {
|
|
|
+ pt = { pt.x - 2, pt.y - 27 };
|
|
|
+ }
|
|
|
+ return ClientToScreen(hWnd, &pt);
|
|
|
+ }
|
|
|
+
|
|
|
+ BOOL ScreenPos2Game(HWND hWnd, POINT& pt)
|
|
|
+ {
|
|
|
+ if (!::IsWindow(hWnd)) return FALSE;
|
|
|
+ return ScreenToClient(hWnd, &pt);
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseMove(POINT pt, bool bSetCurPos)
|
|
|
+ {
|
|
|
+ static long fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN) - 1;
|
|
|
+ static long fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN) - 1;
|
|
|
+ double fx = (double)pt.x * (65535.0f / fScreenWidth);
|
|
|
+ double fy = (double)pt.y * (65535.0f / fScreenHeight);
|
|
|
+#if 1 // mouse_event处理
|
|
|
+ // MOUSEEVENTF_ABSOLUTE 使用绝对鼠标位置;
|
|
|
+ mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, fx, fy, 0, 0);
|
|
|
+#else // setinput处理;
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
|
|
|
+ Input.mi.dx = static_cast<LONG>(fx);
|
|
|
+ Input.mi.dy = static_cast<LONG>(fy);
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ // Move之后要单击,必须setpos;
|
|
|
+ if (bSetCurPos)::SetCursorPos(pt.x, pt.y);
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseClick()
|
|
|
+ {
|
|
|
+ POINT pt;
|
|
|
+ ::GetCursorPos(&pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ Sleep(10);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseClick(POINT pt)
|
|
|
+ {
|
|
|
+ MouseMove(pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ Sleep(10);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseDbClick()
|
|
|
+ {
|
|
|
+ POINT pt;
|
|
|
+ ::GetCursorPos(&pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseDbClick(POINT pt)
|
|
|
+ {
|
|
|
+ MouseMove(pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseRClick()
|
|
|
+ {
|
|
|
+ POINT pt;
|
|
|
+ ::GetCursorPos(&pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_RIGHTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ Sleep(10);
|
|
|
+ mouse_event(MOUSEEVENTF_RIGHTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseRClick(POINT pt)
|
|
|
+ {
|
|
|
+ MouseMove(pt);
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_RIGHTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ Sleep(10);
|
|
|
+ mouse_event(MOUSEEVENTF_RIGHTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void MouseDrag(POINT pt)
|
|
|
+ {
|
|
|
+#if 0
|
|
|
+ // 建议使用这种方式,可以看到鼠标;
|
|
|
+ ::SetCursorPos(pt.x, pt.y); // 必须将鼠标定位到目标单击点;
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
|
|
|
+ Sleep(10);
|
|
|
+ MouseMove(pt, false);
|
|
|
+ Sleep(30);
|
|
|
+ mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
|
|
|
+#else
|
|
|
+ INPUT Input = { 0 };
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dx = pt.x;
|
|
|
+ Input.mi.dy = pt.y;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+
|
|
|
+ Sleep(10);
|
|
|
+ MouseMove(pt, false);
|
|
|
+ Sleep(30);
|
|
|
+ //::ZeroMemory(&Input, sizeof(INPUT));
|
|
|
+ Input.type = INPUT_MOUSE;
|
|
|
+ Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
|
|
+ ::SendInput(1, &Input, sizeof(INPUT));
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ void SendKey(DWORD key, BOOL bCtrl, BOOL bAtl, BOOL bShift)
|
|
|
+ {
|
|
|
+ if (bCtrl)
|
|
|
+ keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
|
+ if (bAtl)
|
|
|
+ keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
|
+ if (bShift)
|
|
|
+ keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
|
+
|
|
|
+ Sleep(120); // 注意:有些电脑能响应Ctrl+V,有些不行,则需要加大CTRL与V之间的时间间隔;
|
|
|
+ // key down;
|
|
|
+ keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
|
|
|
+ // key up;
|
|
|
+ keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
|
+
|
|
|
+ Sleep(120);
|
|
|
+ if (bCtrl)
|
|
|
+ keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
|
+ if (bAtl)
|
|
|
+ keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
|
+ if (bShift)
|
|
|
+ keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
|
+ }
|
|
|
+};
|