Browse Source

更新内容。

Jeff 5 years ago
parent
commit
007e3431fe
1 changed files with 41 additions and 2 deletions
  1. 41 2
      README.md

+ 41 - 2
README.md

@@ -13,14 +13,53 @@
 + 拖动鼠标:
     + 目前遇到技术难点,实现方式不生效:
     + SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
-    + SendMessage(hwnd, WM_MOUSEMOVE, 0,);
+    + SendMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
+    + SendMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
 + 右键鼠标:
     + SendMessage(hwnd, WM_RBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y))
     + SendMessage(hwnd, WM_RBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));
     + 注意:鼠标单击事件时,游戏窗口必须顶层,使用SetForegroundWindow(hwnd)切换窗口到顶层;
 
 ### mouse_event、key_event
-
++ 移动鼠标:
+    + mouse_event(MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
+    + 需要注意的是MOUSEEVENTF_ABSOLUTE宏是绝对坐标,如果没这个宏使用的是相对坐标,换算更麻烦,建议使用绝对坐标;
+单击鼠标:
+    + // 屏幕坐标,窗口坐标需要转成屏幕坐标;
+    + POINT ptScreen = ptWnd; 
+    + ClientToScreen(&ptScreen);
+    + // 窗口必须显示且位于顶层;
+    + ::ShowWindow(hWnd);
+    + ::SetForegroundWindow(hWnd);
+    + // 在单击前,必须将鼠标位置设置在目标点上,否则无效;
+    + ::SetCursorPos(ptScreen.x, ptScreen.y); 
+    + mouse_event(MOUSEEVENTF_LEFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
+	+ mouse_event(MOUSEEVENTF_LEFTUP, ptScreen.x, ptScreen.y, 0, 0);
++ 拖动鼠标:
+    + // 屏幕坐标,窗口坐标需要转成屏幕坐标;
+    + POINT ptSStart = ptWndStart; 
+    + POINT ptSEnd = ptWndEnd; 
+    + ClientToScreen(&ptScreen);
+    + ClientToScreen(&ptSEnd);
+    + // 窗口必须显示且位于顶层;
+    + ::ShowWindow(hWnd);
+    + ::SetForegroundWindow(hWnd);
+    + // 在单击前,必须将鼠标位置设置在目标点上,否则无效;
+    + ::SetCursorPos(ptScreen.x, ptScreen.y); 
+    + mouse_event(MOUSEEVENTF_LEFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
+    + mouse_event(MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE, ptSEnd.x, ptSEnd.y, 0, 0);
+	+ mouse_event(MOUSEEVENTF_LEFTUP, ptSEnd.x, ptSEnd.y, 0, 0);
++ 右键鼠标:
+    + // 屏幕坐标,窗口坐标需要转成屏幕坐标;
+    + POINT ptScreen = ptWnd; 
+    + ClientToScreen(&ptScreen);
+    + // 窗口必须显示且位于顶层;
+    + ::ShowWindow(hWnd);
+    + ::SetForegroundWindow(hWnd);
+    + // 在单击前,必须将鼠标位置设置在目标点上,否则无效;
+    + ::SetCursorPos(ptScreen.x, ptScreen.y); 
+    + mouse_event(MOUSEEVENTF_REFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
+	+ mouse_event(MOUSEEVENTF_REFTUP, ptScreen.x, ptScreen.y, 0, 0);
 
 ## 二、游戏截图与图像处理
 ### 1、GDI截图