Jeff 4 роки тому
батько
коміт
4ca363a925

+ 4 - 2
GameAssist/GameAssist/Assist.cpp

@@ -131,6 +131,7 @@ namespace GAssist
 
 	void ShowLog(const TCHAR* format, ...)
 	{
+		return;
 		// 获取今年年份;
 		__time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
 		struct tm gmtm = { 0 };
@@ -147,8 +148,8 @@ namespace GAssist
 		va_start(args, format);
 		// _vscprintf doesn't count. terminating '\0'
 		len = _vsctprintf(format, args) + 1;
-		buffer = (TCHAR*)malloc(len * sizeof(TCHAR) + 2);
-		_tcscat_s(buffer, len * sizeof(TCHAR) + 2, _T("\n"));
+		buffer = (TCHAR*)malloc(len * sizeof(TCHAR) + 8);
+		_tcscat_s(buffer, len * sizeof(TCHAR) + 8, _T("\n"));
 		_vstprintf_s(buffer, len, format, args);
 		// 将日志内容输入到文件中;
 
@@ -347,6 +348,7 @@ namespace GAssist
 			ClientToScreen(hwnd, &ptScreen);
 		::SetCursorPos(ptScreen.x, ptScreen.y); // 必须将鼠标定位到目标单击点;
 		mouse_event(MOUSEEVENTF_LEFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
+		Sleep(10);
 		mouse_event(MOUSEEVENTF_LEFTUP, ptScreen.x, ptScreen.y, 0, 0);
 #endif
 	}

+ 2 - 1
GameAssist/GameAssist/GameAssist.rc

@@ -87,7 +87,7 @@ BEGIN
     DEFPUSHBUTTON   "È·¶¨",IDOK,113,41,50,14,WS_GROUP
 END
 
-IDD_GAMEASSIST_DIALOG DIALOGEX 0, 0, 139, 202
+IDD_GAMEASSIST_DIALOG DIALOGEX 0, 0, 111, 162
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 EXSTYLE WS_EX_APPWINDOW
 CAPTION "GameAssist"
@@ -99,6 +99,7 @@ BEGIN
     PUSHBUTTON      "Button2",IDC_BUTTON2,8,28,50,14
     PUSHBUTTON      "¾µÑý",IDC_BUTTON3,62,7,50,14
     PUSHBUTTON      "Èý±¶",IDC_BUTTON4,61,29,50,14
+    PUSHBUTTON      "¿ª±¦Ïä",IDC_BUTTON5,5,60,50,14
 END
 
 

+ 5 - 2
GameAssist/GameAssist/GameAssist.vcxproj.filters

@@ -16,6 +16,9 @@
     <Filter Include="task">
       <UniqueIdentifier>{6a5a4f8f-207a-4d61-95f9-080c9f83b59f}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Assist">
+      <UniqueIdentifier>{8099f078-4d90-4f29-a995-7eee6036fdd2}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Assist.cpp">
@@ -43,7 +46,7 @@
       <Filter>源文件</Filter>
     </ClCompile>
     <ClCompile Include="MouseAssist.cpp">
-      <Filter>源文件</Filter>
+      <Filter>Assist</Filter>
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
@@ -78,7 +81,7 @@
       <Filter>头文件</Filter>
     </ClInclude>
     <ClInclude Include="MouseAssist.h">
-      <Filter>头文件</Filter>
+      <Filter>Assist</Filter>
     </ClInclude>
   </ItemGroup>
   <ItemGroup>

+ 120 - 72
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -75,6 +75,7 @@ BEGIN_MESSAGE_MAP(CGameAssistDlg, CDialog)
 	ON_BN_CLICKED(IDC_BUTTON2, &CGameAssistDlg::OnBnClickedButton2)
 	ON_BN_CLICKED(IDC_BUTTON3, &CGameAssistDlg::OnBnClickedButton3)
 	ON_BN_CLICKED(IDC_BUTTON4, &CGameAssistDlg::OnBnClickedButton4)
+	ON_BN_CLICKED(IDC_BUTTON5, &CGameAssistDlg::OnBnClickedButton5)
 END_MESSAGE_MAP()
 
 
@@ -174,13 +175,25 @@ void CGameAssistDlg::OnBnClickedOpengame()
 	TCHAR szWinText[MAX_PATH] = {0};
 	::GetWindowText(hProWnd, szWinText, MAX_PATH);
 
-#if 0
+#if 1
  	Sleep(1000);
- 	GAssist::MouseMove(hProWnd, CPoint(205,150));
+	m_mouseAssist.BindWnd(hProWnd, PT_TYPE::WINDOW_POINT);
+	m_mouseAssist.MoveTo(205, 150);
+	Sleep(1000);
+	m_mouseAssist.MoveTo(250, 250);
+	Sleep(1000);
+	m_mouseAssist.MoveTo(350, 350);
+	Sleep(1000);
+
+	m_mouseAssist.MoveTo(10, 470);
+	m_mouseAssist.LeftClick();
+	/*GAssist::MouseMove(hProWnd, CPoint(205,150));
  	Sleep(2000);
  	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(250,250));
  	Sleep(2000);
- 	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(350,350));
+ 	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(350,350));*/
+
+	return;
 #endif
 
 	if (0)
@@ -460,87 +473,89 @@ void CGameAssistDlg::OnBnClickedButton3()
 		//}
 
 		CRect rc;
-		FIND_NPC(hProWnd, _T("臭美的小米"));
+		//FIND_NPC(hProWnd, _T("臭美的小米"));
 		Sleep(3000);
 		// 与小米对话;
-		if (!GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\1-我帮您抓.bmp"), rc)) {
-			GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-			Sleep(200);
-			// 判断是否还有对话,如果没有的话表明不是第一次进入;
-			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\2-我这就去.bmp"), rc)) {
-				GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+		//if (!GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\1-我帮您抓.bmp"), rc)) {
+		//	GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+		//	Sleep(200);
+		//	// 判断是否还有对话,如果没有的话表明不是第一次进入;
+		//	if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\2-我这就去.bmp"), rc)) {
+		//		GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+		//		Sleep(200);
+		//		// 2次对话;
+		//		if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-幸运镜妖.bmp"), rc)) {
+		//			GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+		//			Sleep(200);
+		//			// 3次对话;
+		//			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-我就选择它.bmp"), rc)) {
+		//				GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+		//				Sleep(200);
+		//			}
+		//		}
+		//	}
+		//	
+		//	
+		//}
+
+		for (int i = 0; i < 20; i++)
+		{
+			// 进入贫民房;
+			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\镜妖1.bmp"), rc)) {
+				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2 - 1, (rc.top + rc.bottom) / 2 - 1));
+				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
 				Sleep(200);
-				// 2次对话;
-				if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-幸运镜妖.bmp"), rc)) {
+				if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\定位镜妖.bmp"), rc)) {
 					GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-					Sleep(200);
-					// 3次对话;
-					if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-我就选择它.bmp"), rc)) {
-						GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-						Sleep(200);
-					}
-				}
-			}
-			
-			for (int i = 0 ; i < 20; i++ )
-			{
-				// 进入贫民房;
-				if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\镜妖1.bmp"), rc)) {
-					GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-					GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2 -1, (rc.top + rc.bottom) / 2 -1));
-					GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-					Sleep(100);
-					if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\定位镜妖.bmp"), rc)) {
+					Sleep(500);
+
+					// 选择我要打你;
+					if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
 						GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
 						Sleep(500);
 
-						// 选择我要打你;
-						if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
-							GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-							Sleep(500);
-
-							// 判断是否在战斗中;
-							while (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\头像.bmp"), rc)) {
-								if (rc.left > 60)
-								{
-									GAssist::ShowLog(_T("战斗中"));
-									GAssist::SendKey(hProWnd, 0x41, FALSE, TRUE);
-									Sleep(3000);
-								}
-								else
-								{
-									GAssist::ShowLog(_T("非战斗"));
-									break;
-								}
+						// 判断是否在战斗中;
+						while (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\头像.bmp"), rc)) {
+							if (rc.left > 60)
+							{
+								GAssist::ShowLog(_T("战斗中"));
+								GAssist::SendKey(hProWnd, 0x41, FALSE, TRUE);
+								Sleep(3000);
+							}
+							else
+							{
+								GAssist::ShowLog(_T("非战斗"));
+								break;
 							}
 						}
 					}
 				}
-				else {
-					static int i = 0;
-					if (i == 0)
-					{
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-						GAssist::MouseClick(hProWnd, CPoint(225, 305));
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-						i++;
-					}
-					else if ( i == 1)
-					{
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-						GAssist::MouseClick(hProWnd, CPoint(300, 266));
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-						i++;
-					}
-					else if (i == 2)
-					{
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-						GAssist::MouseClick(hProWnd, CPoint(175, 280));
-						GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-						i = 0;
-					}
-					Sleep(2000);
+			}
+			else {
+				static int i = 0;
+				if (i == 0)
+				{
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
+					GAssist::MouseClick(hProWnd, CPoint(225, 305));
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
+					i++;
+				}
+				else if (i == 1)
+				{
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
+					GAssist::MouseClick(hProWnd, CPoint(300, 266));
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
+					i++;
 				}
+				else if (i == 2)
+				{
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
+					GAssist::MouseClick(hProWnd, CPoint(175, 280));
+					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
+					i = 0;
+				}
+				Sleep(2000);
 			}
 		}
 
@@ -561,3 +576,36 @@ void CGameAssistDlg::OnBnClickedButton4()
 {
 	// TODO: 在此添加控件通知处理程序代码
 }
+
+
+void CGameAssistDlg::OnBnClickedButton5()
+{
+	// TODO: 在此添加控件通知处理程序代码
+	// 获取进程句柄;
+	DWORD dwPid = GAssist::FindProcess(_T("Game.exe"));
+	HWND hProWnd = GAssist::GetProMainHwnd(dwPid);
+
+
+	if (GAssist::nGameWndType == GAssist::GW_SMALL)
+	{
+		// 对话;
+		CRect rc;
+		for (int i = 0; i < 200; i++)
+		{
+			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\开宝箱\\应天府铁匠.bmp"), rc)) {
+				GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+				Sleep(100);
+				// 判断是否还有对话,如果没有的话表明不是第一次进入;
+				if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\开宝箱\\开宝箱.bmp"), rc)) {
+
+					GAssist::MouseDbClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+					Sleep(200);
+				}
+			}
+
+			Sleep(200);
+		}
+	}
+
+
+}

+ 4 - 1
GameAssist/GameAssist/GameAssistDlg.h

@@ -1,7 +1,7 @@
 
 // GameAssistDlg.h : Í·Îļþ
 //
-
+#include "MouseAssist.h"
 #pragma once
 
 
@@ -29,9 +29,12 @@ protected:
 	afx_msg void OnPaint();
 	afx_msg HCURSOR OnQueryDragIcon();
 	DECLARE_MESSAGE_MAP()
+
+	MouseAssist m_mouseAssist;
 public:
 	afx_msg void OnBnClickedOpengame();
 	afx_msg void OnBnClickedButton2();
 	afx_msg void OnBnClickedButton3();
 	afx_msg void OnBnClickedButton4();
+	afx_msg void OnBnClickedButton5();
 };

+ 321 - 1
GameAssist/GameAssist/MouseAssist.cpp

@@ -3,9 +3,329 @@
 
 MouseAssist::MouseAssist()
 {
-	m_hWnd = NULL;
+	_hWnd = NULL;
+	_nMode = -1;
 }
 
 MouseAssist::~MouseAssist()
 {
+	_hWnd = NULL;
+	_nMode = -1;
 }
+
+void MouseAssist::BindWnd(HWND hWnd, int nMode)
+{
+	_hWnd = hWnd;
+	_nMode = nMode;
+}
+
+void MouseAssist::UnBindWnd()
+{
+	_hWnd = NULL;
+	_nMode = -1;
+}
+
+BOOL MouseAssist::GetCursorPos(long& x, long& y)
+{
+	BOOL bRet = ::GetCursorPos(&_curpt);
+	if (_nMode == PT_TYPE::WINDOW_POINT) {
+		// 窗口句柄判断;
+		if (_hWnd) {
+			bRet = ScreenToClient(_hWnd, &_curpt);
+			if (!bRet)
+				OutputDebugString("坐标转窗口失败\n");
+		}
+	}
+
+	x = _curpt.x;
+	y = _curpt.y;
+
+	return bRet;
+}
+
+inline BOOL MouseAssist::SetCursorPos(int x, int y)
+{
+	_curpt = {x, y};
+	return ::SetCursorPos(x, y);
+}
+
+inline BOOL MouseAssist::MoveTo(int x, int y)
+{
+	_curpt = {x, y};
+	BOOL bRet = FALSE;
+	if ( _nMode == PT_TYPE::SCREEN_POINT) {
+		if ( _hWnd )
+			::ClientToScreen(_hWnd, &_curpt);
+#if 0 // mouse_event处理
+		::SetCursorPos(_curpt.x, _curpt.y);
+		// MOUSEEVENTF_ABSOLUTE 使用绝对鼠标位置;
+		mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, _curpt.x, _curpt.y, 0, 0);
+#else // setinput处理;
+		static long fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN) - 1;
+		static long fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN) - 1;
+		double fx = (double)_curpt.x * (65535.0f / fScreenWidth);
+		double fy = (double)_curpt.y * (65535.0f / fScreenHeight);
+		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);
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	} 
+	else if ( _nMode == PT_TYPE::WINDOW_POINT ) { 
+		// 有时PostMessage才生效;
+		bRet = ::PostMessage(_hWnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::MoveToEx(int x, int y, int w, int h)
+{
+	if (w >= 2 && h >= 2)
+		return MoveTo(x + rand() % w, y + rand() % h);
+	else
+		return MoveTo(x, y);
+}
+
+BOOL MouseAssist::LeftClick()
+{
+	BOOL bRet1 = FALSE;
+	BOOL bRet2 = FALSE;
+	if ( _nMode == PT_TYPE::SCREEN_POINT ) {
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
+		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+
+		::ZeroMemory(&Input, sizeof(INPUT));
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
+		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		//bRet1 = ::SendMessageTimeout(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		//bRet2 = ::SendMessageTimeout(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bRet1 = ::PostMessage(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+		::PostMessage(_hWnd, WM_NCHITTEST, 0, MAKELPARAM(_curpt.x, _curpt.y));
+		::PostMessage(_hWnd, WM_NCHITTEST, HTCLIENT, 0);
+		bRet2 = ::PostMessage(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet1 & bRet2;
+}
+
+BOOL MouseAssist::LeftDoubleClick()
+{
+	BOOL bRet1 = LeftClick();
+	::Sleep(1);
+	BOOL bRet2 = LeftClick();
+
+	return bRet1 & bRet2;
+}
+
+BOOL MouseAssist::LeftDown()
+{
+	BOOL bRet = FALSE;
+	if ( _nMode == PT_TYPE::SCREEN_POINT ) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_LEFTDOWN, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if ( _nMode == PT_TYPE::WINDOW_POINT ) { 
+		bRet = ::PostMessage(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::LeftUp()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_LEFTUP, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::MiddleClick()
+{
+	BOOL bRet1 = FALSE;
+	BOOL bRet2 = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
+		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+
+		::ZeroMemory(&Input, sizeof(INPUT));
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
+		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet1 = ::SendMessageTimeout(_hWnd, WM_MBUTTONDOWN, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bRet2 = ::SendMessageTimeout(_hWnd, WM_MBUTTONUP, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+	}
+
+	return bRet1 & bRet2;
+}
+
+BOOL MouseAssist::MiddleDown()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_MBUTTONDOWN, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+	return bRet;
+}
+
+BOOL MouseAssist::MiddleUp()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_MBUTTONUP, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+	return bRet;
+}
+
+BOOL MouseAssist::RightClick()
+{
+	BOOL bRet1 = FALSE;
+	BOOL bRet2 = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
+		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+
+		::ZeroMemory(&Input, sizeof(INPUT));
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
+		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet1 = ::SendMessageTimeout(_hWnd, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bRet2 = ::SendMessageTimeout(_hWnd, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+	}
+
+	return bRet1 & bRet2;
+}
+
+BOOL MouseAssist::RightDown()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_RIGHTDOWN, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::RightUp()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_RIGHTUP, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::WheelDown()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_RIGHTUP, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_WHEEL;
+		Input.mi.mouseData = WHEEL_DELTA;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_MOUSEWHEEL, MAKEWPARAM(-WHEEL_DELTA, 0), MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+
+BOOL MouseAssist::WheelUp()
+{
+	BOOL bRet = FALSE;
+	if (_nMode == PT_TYPE::SCREEN_POINT) {
+#if 0
+		::SetCursorPos(_curpt.x, _curpt.y);
+		mouse_event(MOUSEEVENTF_RIGHTUP, _curpt.x, _curpt.y, 0, 0);
+#else
+		INPUT Input = { 0 };
+		Input.type = INPUT_MOUSE;
+		Input.mi.dwFlags = MOUSEEVENTF_WHEEL;
+		Input.mi.mouseData = -WHEEL_DELTA;
+		bRet = ::SendInput(1, &Input, sizeof(INPUT));
+#endif
+	}
+	else if (_nMode == PT_TYPE::WINDOW_POINT) {
+		bRet = ::PostMessage(_hWnd, WM_MOUSEWHEEL, MAKEWPARAM(WHEEL_DELTA, 0), MAKELPARAM(_curpt.x, _curpt.y));
+	}
+
+	return bRet;
+}
+

+ 35 - 4
GameAssist/GameAssist/MouseAssist.h

@@ -3,9 +3,11 @@
 
 #pragma once
 
-enum MOUSETYPE
+// 坐标点类型;
+enum PT_TYPE
 {
-
+	SCREEN_POINT,		// 屏幕模式,点是基于屏幕的;
+	WINDOW_POINT		// 窗口模式,点是基于窗口的;
 };
 
 class MouseAssist
@@ -17,9 +19,38 @@ public:
 
 private:
 	// 关联的进程窗口句柄;
-	HWND m_hWnd;
+	HWND _hWnd;
 	// 鼠标是前台模式,还是后台模式;
-	int m_nMode;
+	int _nMode;
+	// 当前点;
+	POINT _curpt;
+public:
+	void BindWnd(HWND hWnd, int nMode);
+	void UnBindWnd();
+	// 获取当前鼠标位置;
+	BOOL GetCursorPos(long &x, long &y);
+	BOOL SetCursorPos(int x, int y);
+
+	// 移动到指定点;注意:点坐标是窗口;
+	BOOL MoveTo(int x, int y);
+	// 在指定范围内随机移动;
+	BOOL MoveToEx(int x, int y, int w, int h);
+
+	BOOL LeftClick();
+	BOOL LeftDoubleClick();
+	BOOL LeftDown();
+	BOOL LeftUp();
+
+	BOOL MiddleClick();
+	BOOL MiddleDown();
+	BOOL MiddleUp();
+
+	BOOL RightClick();
+	BOOL RightDown();
+	BOOL RightUp();
+
+	BOOL WheelDown();
+	BOOL WheelUp();
 };
 
 

+ 2 - 1
GameAssist/GameAssist/resource.h

@@ -12,6 +12,7 @@
 #define IDC_BUTTON2                     1001
 #define IDC_BUTTON3                     1002
 #define IDC_BUTTON4                     1003
+#define IDC_BUTTON5                     1004
 
 // Next default values for new objects
 // 
@@ -19,7 +20,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        129
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         1004
+#define _APS_NEXT_CONTROL_VALUE         1005
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif