{"id":222266,"date":"2021-07-22T08:17:44","date_gmt":"2021-07-22T00:17:44","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=222266"},"modified":"2021-07-07T11:18:41","modified_gmt":"2021-07-07T03:18:41","slug":"python-operate-clipboard","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-operate-clipboard.html","title":{"rendered":"python\u5982\u4f55\u5b9e\u73b0\u526a\u8d34\u677f\u7684\u64cd\u4f5c"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86python\u5b9e\u73b0\u526a\u8d34\u677f\u7684\u64cd\u4f5c\uff0c\u901a\u8fc7\u8f93\u5165\u4e00\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5b9e\u73b0\u5c06\u7279\u5b9a\u7684\u4e00\u4e9b\u6587\u672c\u590d\u5236\u5230\u526a\u8d34\u677f\u7684\u64cd\u4f5c\u3002\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5728\u56de\u7a0b\u7684\u9ad8\u94c1\u4e0a\u5b66\u4e60\u4e86\u8fd9\u4e00\u8282\uff0c\u7531\u4e8e\u5bf9cmd\u547d\u4ee4\u884c\u7684\u76f8\u5173\u77e5\u8bc6\u6240\u77e5\u751a\u5c11\uff0c\u53ea\u80fd\u81ea\u5df1\u4e00\u6b65\u6b65\u8bd5\u9a8c\u5f97\u51fa\u6b63\u786e\u7684\u65b9\u6cd5\uff0c\u56e0\u6b64\u8017\u8d39\u4e86\u4e0d\u5c11\u65f6\u95f4\u3002\u8fd9\u4e00\u7bc7\u535a\u5ba2\u4e5f\u5c31\u5f53\u4f5c\u662f\u5907\u5fd8\u5427\u3002<\/p>\n \u9996\u5148\u8bf4\u4e00\u4e0b\u60f3\u8981\u5b9e\u73b0\u7684\u529f\u80fd\uff1a<\/p>\n \u901a\u8fc7\u8f93\u5165\u4e00\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5b9e\u73b0\u5c06\u7279\u5b9a\u7684\u4e00\u4e9b\u6587\u672c\u590d\u5236\u5230\u526a\u8d34\u677f\u7684\u64cd\u4f5c\u3002\uff08\u8fd9\u4e2a\u7a0b\u5e8f\u6216\u8bb8\u53ef\u4ee5\u4e0e\u5176\u4ed6\u7684\u4e00\u4e9b\u64cd\u4f5c\u76f8\u7ed3\u5408\uff0c\u6765\u5b9e\u73b0\u81ea\u52a8\u56de\u590d\uff0c\u53ea\u662f\u672c\u4eba\u73b0\u9636\u6bb5\u7684\u80fd\u529b\u8fd8\u4e0d\u8db3\u4ee5\u5b9e\u73b0\u8fd9\u6837\u7684\u529f\u80fd\u3002\uff09<\/p>\n \u518d\u6765\u770b\u4e00\u4e0b\u5177\u4f53\u7684\u6b65\u9aa4\u548c\u51e0\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879\uff1a<\/p>\n 1.\u5728python\u6587\u4ef6\u5f00\u5934\u8981\u52a0\u4e0a\u2018#\uff01 python3'\uff0c\u6709\u5173\u4e8e#\uff01\u7684\u5177\u4f53\u542b\u4e49\uff0c\u8be6\u89c1\u6587\u540e\u94fe\u63a5\u3002<\/p>\n 2.\u521b\u5efa\u6279\u5904\u7406\u6587\u4ef6\uff08.bat\uff09\u7684\u8bf4\u660e\uff1a<\/p>\n \u5148\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u6587\u6863\uff08.txt\uff09\uff0c\u5728\u5176\u4e2d\u5199\u5165\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n @py.exe (\u6709\u7a7a\u683c\uff01)\u5c06\u8981\u521b\u5efa\u7684\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u5982E:\\Python\\clipboard_copy (\u53c8\u6709\u7a7a\u683c\uff01)%*<\/p>\n @pause<\/p>\n \u5728\u4f7f\u7528\u4efb\u4f55\u547d\u4ee4\u884c\u65f6\uff0c\u5343\u4e07\u5343\u4e07\u8981\u6ce8\u610f\u7a7a\u683c\uff01\u7531\u4e8e\u547d\u4ee4\u884c\u4e2d\u7684\u53c2\u6570\u662f\u4ee5\u7a7a\u683c\u6765\u5212\u5206\u7684\uff0c\u4efb\u4f55\u975e\u5fc5\u8981\u7684\u7a7a\u683c\u90fd\u53ef\u80fd\u5f15\u8d77\u7cfb\u7edf\u7684\u8bef\u89e3\u56e0\u6b64\u5728\u6587\u4ef6\u8def\u5f84\u4e2d\u7edd\u5bf9\u4e0d\u8981\u51fa\u73b0\u7a7a\u683c\uff0c\u53ef\u7edf\u4e00\u7528\u4e0b\u5212\u7ebf\u6765\u66ff\u6362\uff08\u5e73\u65f6\u7f16\u7a0b\u65f6\u4e00\u5b9a\u8981\u517b\u6210\u826f\u597d\u7684\u6587\u4ef6\u547d\u540d\u4e60\u60ef\u554a\uff09\uff0c\u8fd8\u6709\u5c31\u662f\u6700\u597d\u4e5f\u4e0d\u8981\u5728\u6587\u4ef6\u540d\u4e2d\u51fa\u73b0\u4e2d\u6587\uff0c\u5177\u4f53\u662f\u4e0d\u662f\u56e0\u4e3a\u7f16\u7801\u7684\u539f\u56e0\u6211\u8fd8\u6ca1\u6709\u6d4b\u8bd5\u8fc7\uff0c\u4e0d\u8fc7\u65e2\u7136\u4f1a\u5e26\u6765\u9ebb\u70e6\uff0c\u90a3\u5c31\u8fd8\u662f\u7528\u82f1\u6587\u5427\uff08\u6b63\u597d\u63d0\u5347\u4e00\u4e0b\u82f1\u8bed\u6c34\u5e73\uff09\u3002<\/p>\n \u63a5\u4e0b\u6765\u5c06\u6587\u672c\u6587\u4ef6\u53e6\u5b58\u4e3a.bat\u6587\u4ef6\u683c\u5f0f\uff0c\u8be6\u60c5\u89c1\u4e0b\u56fe\uff1a<\/p>\n <\/p>\n \u5728\u6587\u672c\u6587\u6863\u754c\u9762\u9009\u62e9\u53e6\u5b58\u4e3a\uff08ctrl+shift+S\uff09\uff0c\u6ce8\u610f\u4e0d\u4ec5\u8981\u5c06\u6587\u4ef6\u540e\u7f00\u6539\u6210.bat\uff0c\u8fd8\u8981\u5728\u4fdd\u5b58\u7c7b\u578b\u4e2d\u9009\u62e9\u201c\u6240\u6709\u6587\u4ef6\u201d\u7c7b\u578b \uff1b<\/p>\n \u4fdd\u5b58\u597d\u6279\u5904\u7406\u6587\u4ef6\u4e4b\u540e\uff0c\u5c06\u5176\u79fb\u52a8\u5230C:\\Windows\u76ee\u5f55\u4e0b\uff08\u6216\u8005\u662f\u5176\u4ed6\u4efb\u4f55\u4e00\u4e2a\u5df2\u7ecf\u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\u7684\u8def\u5f84\u5747\u53ef\uff09\u3002<\/p>\n 3.python\u6587\u4ef6\u4e2d\u5177\u4f53\u4ee3\u7801\uff1a<\/p>\n \r\n#! python3\r\n \r\n#TEXT\u4e2d\u662f\u4f60\u60f3\u8981\u590d\u5236\u5230\u526a\u8d34\u677f\u4e0a\u7684\u5185\u5bb9\u548c\u8bbf\u95ee\u4ed6\u4eec\u7684\u5173\u952e\u5b57\u7ec4\u6210\u7684\u5b57\u5178\r\nTEXT = {'\u5fd9': \"\u60a8\u597d\uff0c\u60a8\u6240\u62e8\u6253\u7684\u7528\u6237\u6b63\u5fd9\uff0c\u5982\u9700\u5bf9\u65b9\u56de\u7535\uff0c\u8bf7\u7559\u8a00\uff1a\",\r\n 'busy': \"Sorry, I'm busy now.\",\r\n '\u793e\u4f1a\u4e3b\u4e49\u6838\u5fc3\u4ef7\u503c\u89c2': \"\u5bcc\u5f3a\u6c11\u4e3b\u6587\u660e\u548c\u8c10\\n\u81ea\u7531\u5e73\u7b49\u516c\u6b63\u6cd5\u6cbb\\n\u7231\u56fd\u656c\u4e1a\u8bda\u4fe1\u53cb\u5584\"}\r\n \r\nimport sys, pyperclip\r\nif len(sys.argv) < 2: #\u6b64\u65f6argv\u4e2d\u9664\u4e86\u6587\u4ef6\u540d\u4e4b\u5916\u6ca1\u6709\u4f20\u5165\u5176\u4ed6\u53c2\u6570\r\n print(\"Sorry, no input has been received yet\u2026\")\r\n sys.exit()\r\n \r\nkeyphrase = sys.argv[1]\r\n \r\nif keyphrase in TEXT:\r\n pyperclip.copy(TEXT[keyphrase])\r\n print(\"The text \" + TEXT[keyphrase] + \" is copied to the clipboard\")\r\nelse:\r\n print(\"There is no such text\")\r\n<\/pre>\n |