{"id":1177585,"date":"2025-01-15T17:59:44","date_gmt":"2025-01-15T09:59:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1177585.html"},"modified":"2025-01-15T17:59:47","modified_gmt":"2025-01-15T09:59:47","slug":"python%e5%a6%82%e4%bd%95%e5%86%99%e6%b8%b8%e6%88%8f%e8%be%85%e5%8a%a9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1177585.html","title":{"rendered":"python\u5982\u4f55\u5199\u6e38\u620f\u8f85\u52a9"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25112447\/fb555ede-7271-4835-a717-1241415e62a3.webp\" alt=\"python\u5982\u4f55\u5199\u6e38\u620f\u8f85\u52a9\" \/><\/p>\n<p><p> <strong>Python\u5199\u6e38\u620f\u8f85\u52a9\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u56fe\u50cf\u8bc6\u522b\u3001\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u3001\u5185\u5b58\u8bfb\u53d6\u4e0e\u4fee\u6539\u3001\u5229\u7528\u6e38\u620fAPI\u6216SDK\u3002<\/strong>\u5176\u4e2d\uff0c<strong>\u4f7f\u7528\u56fe\u50cf\u8bc6\u522b<\/strong>\u662f\u4e00\u4e2a\u8f83\u4e3a\u7b80\u5355\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u56fe\u50cf\u8bc6\u522b\u901a\u8fc7\u6355\u6349\u6e38\u620f\u753b\u9762\u5e76\u8bc6\u522b\u7279\u5b9a\u5143\u7d20\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e00\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u56fe\u50cf\u8bc6\u522b\u4e3b\u8981\u4f9d\u8d56\u4e8ePython\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982OpenCV\u548cPillow\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u622a\u53d6\u5c4f\u5e55\u3001\u8bc6\u522b\u56fe\u50cf\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\uff0c\u5e76\u6839\u636e\u8bc6\u522b\u7ed3\u679c\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u7ed3\u5408\u952e\u76d8\u9f20\u6807\u6a21\u62df\u5e93\u5982pyautogui\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u70b9\u51fb\u3001\u79fb\u52a8\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u56fe\u50cf\u8bc6\u522b<\/p>\n<\/p>\n<p><p>\u56fe\u50cf\u8bc6\u522b\u662f\u6e38\u620f\u8f85\u52a9\u4e2d\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u901a\u8fc7\u8bc6\u522b\u6e38\u620f\u753b\u9762\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u3002Python\u4e2d\u5e38\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\u6709OpenCV\u548cPillow\u3002<\/p>\n<\/p>\n<ol>\n<li>OpenCV\u7b80\u4ecb\u53ca\u5b89\u88c5<\/li>\n<\/ol>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u51fd\u6570\u3002\u5b89\u88c5OpenCV\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u622a\u53d6\u5c4f\u5e55\u5e76\u8bc6\u522b\u56fe\u50cf<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u6765\u622a\u53d6\u5c4f\u5e55\u5e76\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002\u5b89\u88c5Pillow\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u622a\u53d6\u5c4f\u5e55\u5e76\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import ImageGrab<\/p>\n<h2><strong>\u622a\u53d6\u5c4f\u5e55<\/strong><\/h2>\n<p>screenshot = ImageGrab.grab()<\/p>\n<h2><strong>\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>screenshot.save(&quot;screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u622a\u53d6\u5c4f\u5e55\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528OpenCV\u6765\u8bc6\u522b\u56fe\u50cf\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\u3002\u4ee5\u8bc6\u522b\u5c4f\u5e55\u4e2d\u7684\u4e00\u4e2a\u7279\u5b9a\u56fe\u6807\u4e3a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u8bfb\u53d6\u622a\u53d6\u7684\u5c4f\u5e55\u56fe\u50cf<\/strong><\/h2>\n<p>screenshot = cv2.imread(&quot;screenshot.png&quot;)<\/p>\n<h2><strong>\u8bfb\u53d6\u8981\u8bc6\u522b\u7684\u56fe\u6807\u56fe\u50cf<\/strong><\/h2>\n<p>icon = cv2.imread(&quot;icon.png&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u6a21\u677f\u5339\u914d\u65b9\u6cd5\u8bc6\u522b\u56fe\u6807\u5728\u5c4f\u5e55\u4e2d\u7684\u4f4d\u7f6e<\/strong><\/h2>\n<p>result = cv2.matchTemplate(screenshot, icon, cv2.TM_CCOEFF_NORMED)<\/p>\n<p>min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)<\/p>\n<h2><strong>\u5982\u679c\u5339\u914d\u5ea6\u9ad8\u4e8e\u67d0\u4e2a\u9608\u503c\uff0c\u5219\u8ba4\u4e3a\u8bc6\u522b\u6210\u529f<\/strong><\/h2>\n<p>threshold = 0.8<\/p>\n<p>if max_val &gt;= threshold:<\/p>\n<p>    print(&quot;Icon found at position:&quot;, max_loc)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Icon not found&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u952e\u76d8\u9f20\u6807\u6a21\u62df<\/li>\n<\/ol>\n<p><p>\u8bc6\u522b\u56fe\u50cf\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528pyautogui\u5e93\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u3002\u5b89\u88c5pyautogui\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pyautogui<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528pyautogui\u5e93\u5b9e\u73b0\u81ea\u52a8\u70b9\u51fb\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyautogui<\/p>\n<h2><strong>\u79fb\u52a8\u9f20\u6807\u5230\u56fe\u6807\u4f4d\u7f6e\u5e76\u70b9\u51fb<\/strong><\/h2>\n<p>icon_position = (max_loc[0], max_loc[1])<\/p>\n<p>pyautogui.moveTo(icon_position)<\/p>\n<p>pyautogui.click()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c<\/p>\n<\/p>\n<p><p>\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u662f\u6e38\u620f\u8f85\u52a9\u7684\u53e6\u4e00\u4e2a\u5e38\u89c1\u65b9\u6cd5\u3002\u901a\u8fc7\u6a21\u62df\u7528\u6237\u8f93\u5165\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u3002Python\u4e2d\u5e38\u7528\u7684\u952e\u76d8\u9f20\u6807\u6a21\u62df\u5e93\u6709pyautogui\u548ckeyboard\u3002<\/p>\n<\/p>\n<ol>\n<li>pyautogui\u7b80\u4ecb\u53ca\u5b89\u88c5<\/li>\n<\/ol>\n<p><p>pyautogui\u662f\u4e00\u4e2a\u53ef\u4ee5\u6a21\u62df\u9f20\u6807\u79fb\u52a8\u3001\u70b9\u51fb\u548c\u952e\u76d8\u8f93\u5165\u7684\u5e93\u3002\u5b89\u88c5pyautogui\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pyautogui<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6a21\u62df\u9f20\u6807\u64cd\u4f5c<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528pyautogui\u5e93\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u9f20\u6807\u7684\u79fb\u52a8\u548c\u70b9\u51fb\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9f20\u6807\u64cd\u4f5c\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyautogui<\/p>\n<h2><strong>\u79fb\u52a8\u9f20\u6807\u5230\u6307\u5b9a\u4f4d\u7f6e<\/strong><\/h2>\n<p>pyautogui.moveTo(100, 100)<\/p>\n<h2><strong>\u79fb\u52a8\u9f20\u6807\u5230\u76f8\u5bf9\u5f53\u524d\u4f4d\u7f6e\u7684\u504f\u79fb\u91cf<\/strong><\/h2>\n<p>pyautogui.moveRel(50, 50)<\/p>\n<h2><strong>\u5728\u6307\u5b9a\u4f4d\u7f6e\u70b9\u51fb\u9f20\u6807<\/strong><\/h2>\n<p>pyautogui.click(200, 200)<\/p>\n<h2><strong>\u53cc\u51fb\u9f20\u6807<\/strong><\/h2>\n<p>pyautogui.doubleClick()<\/p>\n<h2><strong>\u53f3\u952e\u70b9\u51fb<\/strong><\/h2>\n<p>pyautogui.rightClick()<\/p>\n<h2><strong>\u62d6\u52a8\u9f20\u6807<\/strong><\/h2>\n<p>pyautogui.dragTo(300, 300, duration=1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u6a21\u62df\u952e\u76d8\u64cd\u4f5c<\/li>\n<\/ol>\n<p><p>pyautogui\u5e93\u4e5f\u53ef\u4ee5\u6a21\u62df\u952e\u76d8\u8f93\u5165\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u952e\u76d8\u64cd\u4f5c\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyautogui<\/p>\n<h2><strong>\u8f93\u5165\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>pyautogui.typewrite(&quot;Hello, World!&quot;)<\/p>\n<h2><strong>\u6309\u4e0b\u5e76\u91ca\u653e\u952e<\/strong><\/h2>\n<p>pyautogui.press(&quot;enter&quot;)<\/p>\n<h2><strong>\u6309\u4e0b\u7ec4\u5408\u952e<\/strong><\/h2>\n<p>pyautogui.hotkey(&quot;ctrl&quot;, &quot;c&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>keyboard\u5e93\u7b80\u4ecb\u53ca\u5b89\u88c5<\/li>\n<\/ol>\n<p><p>keyboard\u5e93\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u6a21\u62df\u952e\u76d8\u8f93\u5165\u7684\u5e93\uff0c\u652f\u6301\u66f4\u591a\u590d\u6742\u7684\u952e\u76d8\u64cd\u4f5c\u3002\u5b89\u88c5keyboard\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install keyboard<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528keyboard\u5e93\u5b9e\u73b0\u952e\u76d8\u64cd\u4f5c\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import keyboard<\/p>\n<h2><strong>\u6309\u4e0b\u5e76\u91ca\u653e\u952e<\/strong><\/h2>\n<p>keyboard.press_and_release(&quot;shift+a&quot;)<\/p>\n<h2><strong>\u6309\u4e0b\u7ec4\u5408\u952e<\/strong><\/h2>\n<p>keyboard.press_and_release(&quot;ctrl+c&quot;)<\/p>\n<h2><strong>\u8f93\u5165\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>keyboard.write(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5185\u5b58\u8bfb\u53d6\u4e0e\u4fee\u6539<\/p>\n<\/p>\n<p><p>\u5185\u5b58\u8bfb\u53d6\u4e0e\u4fee\u6539\u662f\u6e38\u620f\u8f85\u52a9\u4e2d\u66f4\u4e3a\u9ad8\u7ea7\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u76f4\u63a5\u64cd\u4f5c\u6e38\u620f\u8fdb\u7a0b\u7684\u5185\u5b58\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u4e3a\u7cbe\u7ec6\u7684\u63a7\u5236\u3002Python\u4e2d\u5e38\u7528\u7684\u5185\u5b58\u64cd\u4f5c\u5e93\u6709pymem\u548cctypes\u3002<\/p>\n<\/p>\n<ol>\n<li>pymem\u7b80\u4ecb\u53ca\u5b89\u88c5<\/li>\n<\/ol>\n<p><p>pymem\u662f\u4e00\u4e2a\u7528\u4e8e\u64cd\u4f5c\u8fdb\u7a0b\u5185\u5b58\u7684\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bfb\u53d6\u548c\u4fee\u6539\u5185\u5b58\u6570\u636e\u3002\u5b89\u88c5pymem\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pymem<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u8bfb\u53d6\u8fdb\u7a0b\u5185\u5b58<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528pymem\u5e93\u8bfb\u53d6\u8fdb\u7a0b\u5185\u5b58\u6570\u636e\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pymem<\/p>\n<h2><strong>\u6253\u5f00\u8fdb\u7a0b<\/strong><\/h2>\n<p>pm = pymem.Pymem(&quot;game.exe&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u6a21\u5757\u57fa\u5740<\/strong><\/h2>\n<p>module = pymem.process.module_from_name(pm.process_handle, &quot;game.exe&quot;).lpBaseOfDll<\/p>\n<h2><strong>\u8bfb\u53d6\u5185\u5b58\u6570\u636e<\/strong><\/h2>\n<p>address = module + 0x12345678<\/p>\n<p>value = pm.read_int(address)<\/p>\n<p>print(&quot;Value:&quot;, value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u4fee\u6539\u8fdb\u7a0b\u5185\u5b58<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528pymem\u5e93\u4fee\u6539\u8fdb\u7a0b\u5185\u5b58\u6570\u636e\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pymem<\/p>\n<h2><strong>\u6253\u5f00\u8fdb\u7a0b<\/strong><\/h2>\n<p>pm = pymem.Pymem(&quot;game.exe&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u6a21\u5757\u57fa\u5740<\/strong><\/h2>\n<p>module = pymem.process.module_from_name(pm.process_handle, &quot;game.exe&quot;).lpBaseOfDll<\/p>\n<h2><strong>\u4fee\u6539\u5185\u5b58\u6570\u636e<\/strong><\/h2>\n<p>address = module + 0x12345678<\/p>\n<p>pm.write_int(address, 9999)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5229\u7528\u6e38\u620fAPI\u6216SDK<\/p>\n<\/p>\n<p><p>\u4e00\u4e9b\u6e38\u620f\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684API\u6216SDK\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e9b\u63a5\u53e3\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u548c\u6570\u636e\u83b7\u53d6\u3002\u5229\u7528\u6e38\u620fAPI\u6216SDK\u53ef\u4ee5\u5b9e\u73b0\u66f4\u4e3a\u5b89\u5168\u548c\u7a33\u5b9a\u7684\u6e38\u620f\u8f85\u52a9\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b98\u65b9API\u7b80\u4ecb<\/li>\n<\/ol>\n<p><p>\u4e00\u4e9b\u6e38\u620f\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684API\u63a5\u53e3\uff0c\u53ef\u4ee5\u901a\u8fc7HTTP\u8bf7\u6c42\u83b7\u53d6\u6e38\u620f\u6570\u636e\u3002\u4ee5\u67d0\u4e2a\u6e38\u620f\u7684API\u4e3a\u4f8b\uff0c\u4f7f\u7528requests\u5e93\u83b7\u53d6\u6e38\u620f\u6570\u636e\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u53d1\u9001HTTP\u8bf7\u6c42\u83b7\u53d6\u6e38\u620f\u6570\u636e<\/strong><\/h2>\n<p>response = requests.get(&quot;https:\/\/api.game.com\/player\/stats&quot;)<\/p>\n<p>data = response.json()<\/p>\n<p>print(&quot;Player Stats:&quot;, data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u5b98\u65b9SDK\u7b80\u4ecb<\/li>\n<\/ol>\n<p><p>\u4e00\u4e9b\u6e38\u620f\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684SDK\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e9bSDK\u5b9e\u73b0\u66f4\u4e3a\u590d\u6742\u7684\u64cd\u4f5c\u3002\u4ee5\u67d0\u4e2a\u6e38\u620f\u7684SDK\u4e3a\u4f8b\uff0c\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import game_sdk<\/p>\n<h2><strong>\u521d\u59cb\u5316SDK<\/strong><\/h2>\n<p>sdk = game_sdk.GameSDK(&quot;api_key&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u73a9\u5bb6\u6570\u636e<\/strong><\/h2>\n<p>player_data = sdk.get_player_data(&quot;player_id&quot;)<\/p>\n<p>print(&quot;Player Data:&quot;, player_data)<\/p>\n<h2><strong>\u6267\u884c\u81ea\u52a8\u5316\u64cd\u4f5c<\/strong><\/h2>\n<p>sdk.perform_action(&quot;move&quot;, x=100, y=200)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u7efc\u5408\u793a\u4f8b<\/p>\n<\/p>\n<p><p>\u7ed3\u5408\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u6f14\u793a\u4e86\u4f7f\u7528\u56fe\u50cf\u8bc6\u522b\u3001\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u548c\u5185\u5b58\u8bfb\u53d6\u7684\u7efc\u5408\u5e94\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<p>import pyautogui<\/p>\n<p>import pymem<\/p>\n<p>from PIL import ImageGrab<\/p>\n<h2><strong>\u622a\u53d6\u5c4f\u5e55\u5e76\u8bc6\u522b\u56fe\u6807<\/strong><\/h2>\n<p>screenshot = ImageGrab.grab()<\/p>\n<p>screenshot.save(&quot;screenshot.png&quot;)<\/p>\n<p>screenshot = cv2.imread(&quot;screenshot.png&quot;)<\/p>\n<p>icon = cv2.imread(&quot;icon.png&quot;)<\/p>\n<p>result = cv2.matchTemplate(screenshot, icon, cv2.TM_CCOEFF_NORMED)<\/p>\n<p>min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)<\/p>\n<p>if max_val &gt;= 0.8:<\/p>\n<p>    icon_position = (max_loc[0], max_loc[1])<\/p>\n<p>    print(&quot;Icon found at position:&quot;, icon_position)<\/p>\n<p>    # \u79fb\u52a8\u9f20\u6807\u5230\u56fe\u6807\u4f4d\u7f6e\u5e76\u70b9\u51fb<\/p>\n<p>    pyautogui.moveTo(icon_position)<\/p>\n<p>    pyautogui.click()<\/p>\n<p>    # \u6253\u5f00\u8fdb\u7a0b\u5e76\u8bfb\u53d6\u5185\u5b58\u6570\u636e<\/p>\n<p>    pm = pymem.Pymem(&quot;game.exe&quot;)<\/p>\n<p>    module = pymem.process.module_from_name(pm.process_handle, &quot;game.exe&quot;).lpBaseOfDll<\/p>\n<p>    address = module + 0x12345678<\/p>\n<p>    value = pm.read_int(address)<\/p>\n<p>    print(&quot;Value:&quot;, value)<\/p>\n<p>    # \u4fee\u6539\u5185\u5b58\u6570\u636e<\/p>\n<p>    pm.write_int(address, 9999)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Icon not found&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u3002\u8be5\u7a0b\u5e8f\u53ef\u4ee5\u8bc6\u522b\u6e38\u620f\u4e2d\u7684\u7279\u5b9a\u56fe\u6807\uff0c\u6a21\u62df\u9f20\u6807\u70b9\u51fb\uff0c\u5e76\u8bfb\u53d6\u548c\u4fee\u6539\u6e38\u620f\u5185\u5b58\u6570\u636e\u3002\u901a\u8fc7\u7ed3\u5408\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u4e3a\u590d\u6742\u548c\u5f3a\u5927\u7684\u6e38\u620f\u8f85\u52a9\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u548c\u4f7f\u7528\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5408\u6cd5\u6027\u548c\u9053\u5fb7\u6027<\/strong>\uff1a\u5728\u7f16\u5199\u548c\u4f7f\u7528\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u65f6\uff0c\u5e94\u9075\u5b88\u6e38\u620f\u7684\u4f7f\u7528\u6761\u6b3e\u548c\u6cd5\u5f8b\u6cd5\u89c4\u3002\u4e0d\u8981\u4f7f\u7528\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u8fdb\u884c\u4f5c\u5f0a\u3001\u7834\u574f\u6e38\u620f\u5e73\u8861\u6216\u4fb5\u5bb3\u4ed6\u4eba\u6743\u76ca\u7684\u884c\u4e3a\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u5728\u64cd\u4f5c\u8fdb\u7a0b\u5185\u5b58\u548c\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u65f6\uff0c\u5e94\u786e\u4fdd\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u3002\u907f\u514d\u8bef\u64cd\u4f5c\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u6216\u6570\u636e\u4e22\u5931\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7a33\u5b9a\u6027<\/strong>\uff1a\u5728\u7f16\u5199\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u65f6\uff0c\u5e94\u8003\u8651\u5230\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u3002\u907f\u514d\u56e0\u7a0b\u5e8f\u9519\u8bef\u5bfc\u81f4\u6e38\u620f\u5d29\u6e83\u6216\u5361\u987f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u5728\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u65f6\uff0c\u5e94\u6ce8\u610f\u7a0b\u5e8f\u7684\u6027\u80fd\u4f18\u5316\u3002\u907f\u514d\u9891\u7e41\u7684\u5c4f\u5e55\u622a\u53d6\u548c\u56fe\u50cf\u8bc6\u522b\u5bfc\u81f4\u7cfb\u7edf\u8d44\u6e90\u8017\u5c3d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b66\u4e60\u548c\u7814\u7a76<\/strong>\uff1a\u7f16\u5199\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u662f\u4e00\u4e2a\u5b66\u4e60\u548c\u7814\u7a76\u7684\u8fc7\u7a0b\uff0c\u901a\u8fc7\u4e0d\u65ad\u5c1d\u8bd5\u548c\u4f18\u5316\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7f16\u7a0b\u80fd\u529b\u548c\u89e3\u51b3\u95ee\u9898\u7684\u80fd\u529b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Python\u5199\u6e38\u620f\u8f85\u52a9\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u56fe\u50cf\u8bc6\u522b\u3001\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u3001\u5185\u5b58\u8bfb\u53d6\u4e0e\u4fee\u6539\u3001\u5229\u7528\u6e38\u620fAPI\u6216SDK\u7b49\u3002\u901a\u8fc7\u5408\u7406\u9009\u62e9\u548c\u7ed3\u5408\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u529f\u80fd\u4e30\u5bcc\u3001\u7a33\u5b9a\u9ad8\u6548\u7684\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u3002\u5728\u7f16\u5199\u548c\u4f7f\u7528\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u65f6\uff0c\u5e94\u6ce8\u610f\u5408\u6cd5\u6027\u3001\u5b89\u5168\u6027\u548c\u6027\u80fd\u4f18\u5316\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u7f16\u5199\u6e38\u620f\u8f85\u52a9\u7a0b\u5e8f\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6e38\u620f\u8f85\u52a9\u5de5\u5177\uff1f<\/strong><br \/>\u8981\u521b\u5efa\u4e00\u4e2a\u6e38\u620f\u8f85\u52a9\u5de5\u5177\uff0c\u53ef\u4ee5\u4ecePython\u7684\u57fa\u672c\u5e93\u5f00\u59cb\uff0c\u4f8b\u5982\u4f7f\u7528<code>Pygame<\/code>\u6765\u5904\u7406\u56fe\u5f62\u548c\u58f0\u97f3\uff0c\u6216\u8005\u4f7f\u7528<code>pyautogui<\/code>\u6765\u5b9e\u73b0\u81ea\u52a8\u5316\u64cd\u4f5c\u3002\u9996\u5148\uff0c\u786e\u5b9a\u8f85\u52a9\u5de5\u5177\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u81ea\u52a8\u70b9\u51fb\u3001\u754c\u9762\u4fe1\u606f\u63d0\u53d6\u6216\u6570\u636e\u5206\u6790\u3002\u63a5\u7740\uff0c\u5b66\u4e60\u76f8\u5173\u5e93\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u7f16\u5199\u811a\u672c\uff0c\u5e76\u8fdb\u884c\u6d4b\u8bd5\u4ee5\u786e\u4fdd\u5176\u5728\u6e38\u620f\u4e2d\u8868\u73b0\u826f\u597d\u3002<\/p>\n<p><strong>Python\u7f16\u5199\u7684\u6e38\u620f\u8f85\u52a9\u5de5\u5177\u53ef\u4ee5\u7528\u4e8e\u54ea\u4e9b\u6e38\u620f\u7c7b\u578b\uff1f<\/strong><br \/>Python\u7f16\u5199\u7684\u6e38\u620f\u8f85\u52a9\u5de5\u5177\u901a\u5e38\u9002\u7528\u4e8e\u8bb8\u591a\u7c7b\u578b\u7684\u6e38\u620f\uff0c\u5305\u62ec\u4f11\u95f2\u6e38\u620f\u3001\u7f51\u9875\u6e38\u620f\u3001\u751a\u81f3\u4e00\u4e9bPC\u6e38\u620f\u3002\u5bf9\u4e8e\u9700\u8981\u5927\u91cf\u91cd\u590d\u6027\u64cd\u4f5c\u6216\u6570\u636e\u6536\u96c6\u7684\u6e38\u620f\uff0c\u8f85\u52a9\u5de5\u5177\u5c24\u5176\u6709\u6548\u3002\u4f8b\u5982\uff0c\u89d2\u8272\u626e\u6f14\u6e38\u620f\uff08RPG\uff09\u4e2d\u53ef\u4ee5\u4f7f\u7528\u8f85\u52a9\u5de5\u5177\u6765\u81ea\u52a8\u6253\u602a\u3001\u6536\u96c6\u8d44\u6e90\uff0c\u6216\u8005\u5728\u7b56\u7565\u6e38\u620f\u4e2d\u8fdb\u884c\u5feb\u901f\u70b9\u51fb\u548c<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/58557.html\" target=\"_blank\">\u8d44\u6e90\u7ba1\u7406<\/a>\u3002<\/p>\n<p><strong>\u5728\u7f16\u5199\u6e38\u620f\u8f85\u52a9\u5de5\u5177\u65f6\uff0c\u6709\u54ea\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u6cd5\u5f8b\u6216\u9053\u5fb7\u95ee\u9898\uff1f<\/strong><br \/>\u521b\u5efa\u6e38\u620f\u8f85\u52a9\u5de5\u5177\u65f6\uff0c\u9700\u786e\u4fdd\u9075\u5faa\u6e38\u620f\u7684\u4f7f\u7528\u6761\u6b3e\u548c\u670d\u52a1\u534f\u8bae\u3002\u8bb8\u591a\u6e38\u620f\u660e\u786e\u7981\u6b62\u4f7f\u7528\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u8fdb\u884c\u81ea\u52a8\u5316\u6216\u4f5c\u5f0a\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u8d26\u53f7\u88ab\u5c01\u7981\u3002\u6b64\u5916\uff0c\u8003\u8651\u5230\u6e38\u620f\u7684\u516c\u5e73\u6027\uff0c\u4f7f\u7528\u8f85\u52a9\u5de5\u5177\u65f6\u5e94\u8c28\u614e\uff0c\u5c0a\u91cd\u5176\u4ed6\u73a9\u5bb6\u7684\u6e38\u620f\u4f53\u9a8c\uff0c\u907f\u514d\u7834\u574f\u6e38\u620f\u7684\u5e73\u8861\u6027\u548c\u4e50\u8da3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5199\u6e38\u620f\u8f85\u52a9\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u56fe\u50cf\u8bc6\u522b\u3001\u6a21\u62df\u952e\u76d8\u9f20\u6807\u64cd\u4f5c\u3001\u5185\u5b58\u8bfb\u53d6\u4e0e\u4fee\u6539\u3001\u5229\u7528\u6e38\u620fAPI\u6216SDK\u3002\u5176\u4e2d\uff0c [&hellip;]","protected":false},"author":3,"featured_media":1177594,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177585"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1177585"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177585\/revisions"}],"predecessor-version":[{"id":1177596,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177585\/revisions\/1177596"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1177594"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1177585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1177585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1177585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}