{"id":1093377,"date":"2025-01-08T14:30:33","date_gmt":"2025-01-08T06:30:33","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1093377.html"},"modified":"2025-01-08T14:30:36","modified_gmt":"2025-01-08T06:30:36","slug":"python%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e9%94%ae%e7%9b%98%e4%b8%8a%e7%9a%84%e7%89%b9%e6%ae%8a%e5%ad%97%e7%ac%a6-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1093377.html","title":{"rendered":"python\u5982\u4f55\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210005\/b65654a9-3133-47ec-b2d9-dabdf9f6cee7.webp\" alt=\"python\u5982\u4f55\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26<\/strong><\/p>\n<\/p>\n<p><p><strong>Python\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\u53ef\u4ee5\u4f7f\u7528\u5e93\u5982<code>keyboard<\/code>\u3001<code>pynput<\/code>\u3001<code>tkinter<\/code>\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528<code>keyboard<\/code>\u5e93\u76f8\u5bf9\u7b80\u5355\u548c\u76f4\u89c2\u3002<code>keyboard<\/code>\u5e93\u63d0\u4f9b\u4e86\u5bf9\u952e\u76d8\u4e8b\u4ef6\u7684\u76d1\u63a7\u548c\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5224\u65ad\u7528\u6237\u662f\u5426\u6309\u4e0b\u4e86\u7279\u6b8a\u5b57\u7b26\u952e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>keyboard<\/code>\u5e93<\/h3>\n<\/p>\n<p><p><code>keyboard<\/code>\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e93\uff0c\u5b83\u5141\u8bb8\u4f60\u8bb0\u5f55\u548c\u64ad\u653e\u952e\u76d8\u4e8b\u4ef6\u3001\u6302\u94a9\u5168\u5c40\u4e8b\u4ef6\u4ee5\u53ca\u53d1\u9001\u865a\u62df\u952e\u76d8\u4e8b\u4ef6\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>keyboard<\/code>\u5e93\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5<code>keyboard<\/code>\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5<code>keyboard<\/code>\u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install keyboard<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u76d1\u542c\u952e\u76d8\u4e8b\u4ef6<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u76d1\u542c\u952e\u76d8\u4e8b\u4ef6\uff0c\u5e76\u5224\u65ad\u662f\u5426\u6309\u4e0b\u4e86\u7279\u6b8a\u5b57\u7b26\u952e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import keyboard<\/p>\n<p>def on_key_event(event):<\/p>\n<p>    # \u5224\u65ad\u6309\u4e0b\u7684\u662f\u5426\u4e3a\u7279\u6b8a\u5b57\u7b26\u952e<\/p>\n<p>    if event.name in [&#39;!&#39;, &#39;@&#39;, &#39;#&#39;, &#39;$&#39;, &#39;%&#39;, &#39;^&#39;, &#39;&amp;&#39;, &#39;*&#39;, &#39;(&#39;, &#39;)&#39;, &#39;_&#39;, &#39;+&#39;]:<\/p>\n<p>        print(f&quot;Special character &#39;{event.name}&#39; pressed&quot;)<\/p>\n<h2><strong>\u6ce8\u518c\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u5668<\/strong><\/h2>\n<p>keyboard.on_press(on_key_event)<\/p>\n<h2><strong>\u4fdd\u6301\u811a\u672c\u8fd0\u884c<\/strong><\/h2>\n<p>keyboard.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>t(&#39;esc&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>on_key_event<\/code>\u51fd\u6570\u4f1a\u5728\u6bcf\u6b21\u6309\u952e\u65f6\u88ab\u8c03\u7528\u3002\u5982\u679c\u6309\u4e0b\u7684\u952e\u662f\u7279\u6b8a\u5b57\u7b26\u952e\uff08\u5982<code>!<\/code>\u3001<code>@<\/code>\u3001<code>#<\/code>\u7b49\uff09\uff0c\u5219\u4f1a\u6253\u5370\u76f8\u5e94\u7684\u6d88\u606f\u3002\u811a\u672c\u4f1a\u4e00\u76f4\u8fd0\u884c\uff0c\u76f4\u5230\u4f60\u6309\u4e0b<code>Esc<\/code>\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528<code>pynput<\/code>\u5e93<\/h3>\n<\/p>\n<p><p><code>pynput<\/code>\u5e93\u4e5f\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u952e\u76d8\u548c\u9f20\u6807\u4e8b\u4ef6\u76d1\u542c\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u5bf9\u952e\u76d8\u4e8b\u4ef6\u7684\u5168\u9762\u652f\u6301\uff0c\u5141\u8bb8\u4f60\u76d1\u542c\u952e\u76d8\u6309\u952e\u5e76\u505a\u51fa\u76f8\u5e94\u7684\u53cd\u5e94\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5<code>pynput<\/code>\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5<code>pynput<\/code>\u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pynput<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u76d1\u542c\u952e\u76d8\u4e8b\u4ef6<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u76d1\u542c\u952e\u76d8\u4e8b\u4ef6\uff0c\u5e76\u5224\u65ad\u662f\u5426\u6309\u4e0b\u4e86\u7279\u6b8a\u5b57\u7b26\u952e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pynput import keyboard<\/p>\n<p>def on_press(key):<\/p>\n<p>    try:<\/p>\n<p>        # \u5224\u65ad\u6309\u4e0b\u7684\u662f\u5426\u4e3a\u7279\u6b8a\u5b57\u7b26\u952e<\/p>\n<p>        if key.char in [&#39;!&#39;, &#39;@&#39;, &#39;#&#39;, &#39;$&#39;, &#39;%&#39;, &#39;^&#39;, &#39;&amp;&#39;, &#39;*&#39;, &#39;(&#39;, &#39;)&#39;, &#39;_&#39;, &#39;+&#39;]:<\/p>\n<p>            print(f&quot;Special character &#39;{key.char}&#39; pressed&quot;)<\/p>\n<p>    except AttributeError:<\/p>\n<p>        pass<\/p>\n<h2><strong>\u6ce8\u518c\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u5668<\/strong><\/h2>\n<p>with keyboard.Listener(on_press=on_press) as listener:<\/p>\n<p>    listener.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>on_press<\/code>\u51fd\u6570\u4f1a\u5728\u6bcf\u6b21\u6309\u952e\u65f6\u88ab\u8c03\u7528\u3002\u5982\u679c\u6309\u4e0b\u7684\u952e\u662f\u7279\u6b8a\u5b57\u7b26\u952e\uff08\u5982<code>!<\/code>\u3001<code>@<\/code>\u3001<code>#<\/code>\u7b49\uff09\uff0c\u5219\u4f1a\u6253\u5370\u76f8\u5e94\u7684\u6d88\u606f\u3002\u811a\u672c\u4f1a\u4e00\u76f4\u8fd0\u884c\uff0c\u76f4\u5230\u4f60\u624b\u52a8\u505c\u6b62\u5b83\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528<code>tkinter<\/code>\u5e93<\/h3>\n<\/p>\n<p><p><code>tkinter<\/code>\u5e93\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u7528\u4e8e\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u5de5\u5177\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>tkinter<\/code>\u5e93\u6765\u76d1\u542c\u952e\u76d8\u4e8b\u4ef6\uff0c\u5e76\u5224\u65ad\u662f\u5426\u6309\u4e0b\u4e86\u7279\u6b8a\u5b57\u7b26\u952e\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa<code>tkinter<\/code>\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a<code>tkinter<\/code>\u7a97\u53e3\uff0c\u5e76\u7ed1\u5b9a\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u5668\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>def on_key_event(event):<\/p>\n<p>    # \u5224\u65ad\u6309\u4e0b\u7684\u662f\u5426\u4e3a\u7279\u6b8a\u5b57\u7b26\u952e<\/p>\n<p>    if event.char in [&#39;!&#39;, &#39;@&#39;, &#39;#&#39;, &#39;$&#39;, &#39;%&#39;, &#39;^&#39;, &#39;&amp;&#39;, &#39;*&#39;, &#39;(&#39;, &#39;)&#39;, &#39;_&#39;, &#39;+&#39;]:<\/p>\n<p>        print(f&quot;Special character &#39;{event.char}&#39; pressed&quot;)<\/p>\n<h2><strong>\u521b\u5efatkinter\u7a97\u53e3<\/strong><\/h2>\n<p>root = tk.Tk()<\/p>\n<p>root.bind(&#39;&lt;KeyPress&gt;&#39;, on_key_event)<\/p>\n<h2><strong>\u8fd0\u884ctkinter\u4e3b\u5faa\u73af<\/strong><\/h2>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>on_key_event<\/code>\u51fd\u6570\u4f1a\u5728\u6bcf\u6b21\u6309\u952e\u65f6\u88ab\u8c03\u7528\u3002\u5982\u679c\u6309\u4e0b\u7684\u952e\u662f\u7279\u6b8a\u5b57\u7b26\u952e\uff08\u5982<code>!<\/code>\u3001<code>@<\/code>\u3001<code>#<\/code>\u7b49\uff09\uff0c\u5219\u4f1a\u6253\u5370\u76f8\u5e94\u7684\u6d88\u606f\u3002<code>tkinter<\/code>\u7a97\u53e3\u4f1a\u4e00\u76f4\u8fd0\u884c\uff0c\u76f4\u5230\u4f60\u5173\u95ed\u5b83\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528<code>keyboard<\/code>\u3001<code>pynput<\/code>\u548c<code>tkinter<\/code>\u5e93\u6765\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\u3002<strong>\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f<\/strong>\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. <code>keyboard<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>keyboard<\/code>\u5e93\u975e\u5e38\u9002\u5408\u9700\u8981\u5168\u5c40\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u7684\u573a\u666f\u3002\u5b83\u53ef\u4ee5\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u5e76\u4e14\u4e0d\u9700\u8981\u989d\u5916\u7684\u7a97\u53e3\u6216\u754c\u9762\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>keyboard<\/code>\u5e93\u6765\u5b9e\u73b0\u590d\u6742\u7684\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u5982\u70ed\u952e\u89e6\u53d1\u3001\u5b8f\u5f55\u5236\u548c\u64ad\u653e\u7b49\u3002<\/p>\n<\/p>\n<p><h4>2. <code>pynput<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>pynput<\/code>\u5e93\u540c\u6837\u9002\u5408\u9700\u8981\u5168\u5c40\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u7684\u573a\u666f\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u4e3a\u8be6\u7ec6\u7684\u952e\u76d8\u4e8b\u4ef6\u4fe1\u606f\uff0c\u5e76\u4e14\u652f\u6301\u8de8\u5e73\u53f0\u64cd\u4f5c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pynput<\/code>\u5e93\u6765\u5b9e\u73b0\u66f4\u52a0\u7cbe\u7ec6\u7684\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u5982\u6309\u952e\u7ec4\u5408\u89e6\u53d1\u3001\u6309\u952e\u6301\u7eed\u65f6\u95f4\u68c0\u6d4b\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3. <code>tkinter<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>tkinter<\/code>\u5e93\u975e\u5e38\u9002\u5408\u9700\u8981\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u573a\u666f\u3002\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u7a97\u53e3\uff0c\u5e76\u4e14\u652f\u6301\u4e30\u5bcc\u7684GUI\u63a7\u4ef6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>tkinter<\/code>\u5e93\u6765\u5b9e\u73b0\u5e26\u6709\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u529f\u80fd\u7684\u56fe\u5f62\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982\u6587\u672c\u7f16\u8f91\u5668\u3001\u6e38\u620f\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c<strong>\u5173\u952e\u5728\u4e8e\u5bf9\u952e\u76d8\u4e8b\u4ef6\u7684\u76d1\u542c\u548c\u5904\u7406<\/strong>\u3002\u901a\u8fc7\u5408\u7406\u7684\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u7279\u6b8a\u5b57\u7b26\u952e\u7684\u68c0\u6d4b\u548c\u54cd\u5e94\uff0c\u4ece\u800c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6269\u5c55\u9605\u8bfb<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u4e09\u79cd\u65b9\u6cd5\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5e93\u548c\u5de5\u5177\u53ef\u4ee5\u7528\u4e8e\u952e\u76d8\u4e8b\u4ef6\u76d1\u542c\u548c\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u503c\u5f97\u63a2\u7d22\u7684\u5e93\u548c\u5de5\u5177\uff1a<\/p>\n<\/p>\n<p><h4>1. <code>pyHook<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>pyHook<\/code>\u5e93\u662fWindows\u5e73\u53f0\u4e0a\u5e38\u7528\u7684\u952e\u76d8\u548c\u9f20\u6807\u4e8b\u4ef6\u76d1\u542c\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u5bf9\u5168\u5c40\u952e\u76d8\u548c\u9f20\u6807\u4e8b\u4ef6\u7684\u5168\u9762\u652f\u6301\uff0c\u5141\u8bb8\u4f60\u5728\u540e\u53f0\u76d1\u542c\u548c\u5904\u7406\u4e8b\u4ef6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pyHook<\/code>\u5e93\u6765\u5b9e\u73b0\u590d\u6742\u7684\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u5982\u952e\u76d8\u8bb0\u5f55\u3001\u6309\u952e\u8fc7\u6ee4\u7b49\u3002<\/p>\n<\/p>\n<p><h4>2. <code>AutoHotkey<\/code><\/h4>\n<\/p>\n<p><p><code>AutoHotkey<\/code>\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u81ea\u52a8\u5316\u811a\u672c\u8bed\u8a00\uff0c\u652f\u6301\u952e\u76d8\u548c\u9f20\u6807\u4e8b\u4ef6\u7684\u76d1\u542c\u548c\u5904\u7406\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>AutoHotkey<\/code>\u6765\u7f16\u5199\u811a\u672c\uff0c\u5b9e\u73b0\u5bf9\u952e\u76d8\u4e8b\u4ef6\u7684\u76d1\u63a7\u548c\u54cd\u5e94\u3002<code>AutoHotkey<\/code>\u7279\u522b\u9002\u5408\u9700\u8981\u5feb\u901f\u5b9e\u73b0\u952e\u76d8\u5b8f\u3001\u70ed\u952e\u7b49\u529f\u80fd\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>3. <code>Qt<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>Qt<\/code>\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684C++\u56fe\u5f62\u7528\u6237\u754c\u9762\u5e93\uff0c\u652f\u6301\u952e\u76d8\u4e8b\u4ef6\u7684\u76d1\u542c\u548c\u5904\u7406\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>Qt<\/code>\u5e93\u6765\u521b\u5efa\u5e26\u6709\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u529f\u80fd\u7684\u56fe\u5f62\u5e94\u7528\u7a0b\u5e8f\u3002<code>Qt<\/code>\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63a7\u4ef6\u548c\u5de5\u5177\uff0c\u9002\u5408\u9700\u8981\u9ad8\u7ea7\u56fe\u5f62\u754c\u9762\u548c\u590d\u6742\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>1. \u6e38\u620f\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u90e8\u5206\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u6765\u76d1\u542c\u548c\u5904\u7406\u73a9\u5bb6\u7684\u6309\u952e\u8f93\u5165\uff0c\u4ece\u800c\u5b9e\u73b0\u6e38\u620f\u89d2\u8272\u7684\u79fb\u52a8\u3001\u653b\u51fb\u3001\u8df3\u8dc3\u7b49\u64cd\u4f5c\u3002\u901a\u8fc7\u5408\u7406\u7684\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u4f60\u53ef\u4ee5\u63d0\u4f9b\u6d41\u7545\u7684\u6e38\u620f\u4f53\u9a8c\u548c\u54cd\u5e94\u8fc5\u901f\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>2. \u6587\u672c\u7f16\u8f91\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\uff0c\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u540c\u6837\u81f3\u5173\u91cd\u8981\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u6765\u76d1\u542c\u548c\u5904\u7406\u7528\u6237\u7684\u6309\u952e\u8f93\u5165\uff0c\u4ece\u800c\u5b9e\u73b0\u6587\u672c\u7684\u7f16\u8f91\u3001\u5220\u9664\u3001\u590d\u5236\u3001\u7c98\u8d34\u7b49\u64cd\u4f5c\u3002\u901a\u8fc7\u5408\u7406\u7684\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u4f60\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6548\u7684\u6587\u672c\u7f16\u8f91\u529f\u80fd\u548c\u4fbf\u6377\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<p><h4>3. \u81ea\u52a8\u5316\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u81ea\u52a8\u5316\u811a\u672c\u4e2d\uff0c\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u53ef\u4ee5\u7528\u4e8e\u81ea\u52a8\u6267\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u6765\u76d1\u542c\u548c\u5904\u7406\u6309\u952e\u8f93\u5165\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u52a8\u5316\u4efb\u52a1\u7684\u89e6\u53d1\u548c\u6267\u884c\u3002\u901a\u8fc7\u5408\u7406\u7684\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u4f60\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\uff0c\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528<code>keyboard<\/code>\u3001<code>pynput<\/code>\u548c<code>tkinter<\/code>\u5e93\u6765\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f\uff0c<strong>\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u65b9\u6cd5<\/strong>\u3002<\/p>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u4ecb\u7ecd\u4e86\u4e00\u4e9b\u5176\u4ed6\u503c\u5f97\u63a2\u7d22\u7684\u5e93\u548c\u5de5\u5177\uff0c\u5982<code>pyHook<\/code>\u3001<code>AutoHotkey<\/code>\u548c<code>Qt<\/code>\u5e93\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u5173\u952e\u5728\u4e8e\u5bf9\u952e\u76d8\u4e8b\u4ef6\u7684\u76d1\u542c\u548c\u5904\u7406\u3002\u901a\u8fc7\u5408\u7406\u7684\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u7279\u6b8a\u5b57\u7b26\u952e\u7684\u68c0\u6d4b\u548c\u54cd\u5e94\uff0c\u4ece\u800c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u7406\u89e3\u548c\u5b9e\u73b0\u952e\u76d8\u4e8b\u4ef6\u5904\u7406\u6709\u6240\u5e2e\u52a9\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u9700\u8981\u8fdb\u4e00\u6b65\u7684\u5e2e\u52a9\uff0c\u8bf7\u968f\u65f6\u4e0e\u6211\u8054\u7cfb\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bc6\u522b\u7279\u6b8a\u5b57\u7b26\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5185\u7f6e\u65b9\u6cd5\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u5e93\u6765\u8bc6\u522b\u548c\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u4ec0\u4e48\u662f\u201c\u7279\u6b8a\u5b57\u7b26\u201d\uff0c\u4f8b\u5982\uff0c\u662f\u5426\u5305\u62ec\u6807\u70b9\u7b26\u53f7\u3001\u7a7a\u683c\u6216\u5176\u4ed6\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\uff0c\u6765\u8fdb\u884c\u76f8\u5e94\u7684\u5224\u65ad\u3002\u4f7f\u7528<code>re<\/code>\u6a21\u5757\u7684<code>re.search()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u67e5\u627e\u662f\u5426\u5b58\u5728\u8fd9\u4e9b\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u68c0\u6d4b\u8f93\u5165\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\uff1f<\/strong><br \/>\u68c0\u6d4b\u8f93\u5165\u4e2d\u662f\u5426\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u96c6\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u901a\u8fc7<code>string<\/code>\u6a21\u5757\u4e2d\u7684<code>punctuation<\/code>\uff0c\u7ed3\u5408<code>any()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5feb\u901f\u5224\u65ad\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u542b\u6709\u6807\u70b9\u7b26\u53f7\u3002\u6b64\u5916\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u7075\u6d3b\u6027\u4f7f\u5f97\u4f60\u53ef\u4ee5\u8f7b\u677e\u5b9a\u4e49\u4ec0\u4e48\u5b57\u7b26\u5c5e\u4e8e\u201c\u7279\u6b8a\u5b57\u7b26\u201d\uff0c\u5e76\u8fdb\u884c\u5339\u914d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1f<\/strong><br \/>\u5904\u7406\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>str.replace()<\/code>\u65b9\u6cd5\u6765\u66ff\u6362\u6216\u5220\u9664\u8fd9\u4e9b\u5b57\u7b26\uff0c\u6216\u8005\u4f7f\u7528<code>str.translate()<\/code>\u4e0e<code>str.maketrans()<\/code>\u7ec4\u5408\u6765\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u66ff\u6362\u903b\u8f91\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7075\u6d3b\u5730\u5339\u914d\u5e76\u5904\u7406\u4e0d\u540c\u79cd\u7c7b\u7684\u7279\u6b8a\u5b57\u7b26\uff0c\u786e\u4fdd\u5b57\u7b26\u4e32\u7b26\u5408\u9884\u671f\u683c\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26 Python\u5224\u65ad\u952e\u76d8\u4e0a\u7684\u7279\u6b8a\u5b57\u7b26\u53ef\u4ee5\u4f7f\u7528\u5e93\u5982keyboard\u3001pynpu [&hellip;]","protected":false},"author":3,"featured_media":1093386,"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\/1093377"}],"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=1093377"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1093377\/revisions"}],"predecessor-version":[{"id":1093391,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1093377\/revisions\/1093391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1093386"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1093377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1093377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1093377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}