├── requirements.txt
├── img_1.png
├── .idea
├── .gitignore
├── vcs.xml
├── inspectionProfiles
│ └── profiles_settings.xml
├── modules.xml
├── misc.xml
└── Paste.iml
├── LICENSE
├── .github
└── workflows
│ └── build.yml
├── README.md
└── auto_input_tool.py
/requirements.txt:
--------------------------------------------------------------------------------
1 | pynput~=1.8.1
2 | pyperclip~=1.9.0
--------------------------------------------------------------------------------
/img_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/colorcard/AutoInputTool/HEAD/img_1.png
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # 默认忽略的文件
2 | /shelf/
3 | /workspace.xml
4 | # 基于编辑器的 HTTP 客户端请求
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/Paste.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 colorcard
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build EXE and APP
2 |
3 | on:
4 | push:
5 | branches:
6 | - main # 当代码推送到 main 分支时触发构建
7 | workflow_dispatch: # 允许手动触发
8 |
9 | jobs:
10 | build_windows:
11 | runs-on: windows-latest # 使用 Windows 环境
12 |
13 | steps:
14 | - name: Checkout code
15 | uses: actions/checkout@v3 # 检出代码
16 |
17 | - name: Set up Python
18 | uses: actions/setup-python@v4
19 | with:
20 | python-version: '3.12' # 设置 Python 版本
21 |
22 | - name: Install dependencies
23 | run: |
24 | python -m pip install --upgrade pip
25 | pip install -r requirements.txt # 安装依赖
26 |
27 | - name: Install PyInstaller
28 | run: pip install pyinstaller # 安装 PyInstaller
29 |
30 | - name: Build EXE for Windows
31 | run: pyinstaller --onefile --hidden-import pynput --hidden-import pyperclip --noconsole auto_input_tool.py
32 |
33 | - name: Upload Windows EXE artifact
34 | uses: actions/upload-artifact@v4 # 升级到 v4 版本
35 | with:
36 | name: auto-input-tool-exe
37 | path: dist/auto_input_tool.exe # 上传生成的 EXE 文件
38 |
39 | build_macos:
40 | runs-on: macos-latest # 使用 macOS 环境
41 |
42 | steps:
43 | - name: Checkout code
44 | uses: actions/checkout@v3 # 检出代码
45 |
46 | - name: Set up Python
47 | uses: actions/setup-python@v4
48 | with:
49 | python-version: '3.12' # 设置 Python 版本
50 |
51 | - name: Install dependencies
52 | run: |
53 | python -m pip install --upgrade pip
54 | pip install -r requirements.txt # 安装依赖
55 |
56 | - name: Install PyInstaller
57 | run: pip install pyinstaller # 安装 PyInstaller
58 |
59 | - name: Build APP for macOS
60 | run: pyinstaller --onefile --hidden-import pynput --hidden-import pyperclip --windowed auto_input_tool.py
61 |
62 | - name: Upload macOS APP artifact
63 | uses: actions/upload-artifact@v4 # 升级到 v4 版本
64 | with:
65 | name: auto-input-tool-app
66 | path: dist/auto_input_tool.app # 上传生成的 macOS APP 文件
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 自动输入工具使用文档
2 |
3 | ## 简介
4 | 
5 |
6 | 此工具使用 Python 和 Tkinter 库创建了一个简单的自动输入应用。用户可以在应用的文本框中输入或粘贴文本,并点击“开始输入”按钮,程序将模拟键盘输入这些文本。
7 |
8 | 可以用来规避例如头歌平台此类**禁止粘贴**的场景(注意在自动补全的情况下可能会出现错误),欢迎各位提交 **issue** 和 **Pr**,觉得有用的话留下一个 **Star⭐️** 吧!
9 |
10 |
11 |
12 |
13 | ## 功能
14 | 1. 提供一个文本框,允许用户输入或粘贴文本。
15 | 2. 点击“开始输入”按钮后,程序会模拟键盘输入文本框中的内容。
16 | 3. 具有 3 秒的延迟,给用户一些准备时间。
17 |
18 | ## !! 面向小白 !!
19 | 如果你不具备进行构建和运行Python脚本的能力,此工具也已经构建了现有的直接可执行程序,请在此进行下载 [Windows & macOS下载](https://github.com/ColorCard/AutoInputTool/releases/tag/%E6%AD%A3%E5%BC%8F%E7%89%88)。
20 |
21 | ---
22 |
23 | ## 环境要求
24 | - Python 3.12 及以上版本
25 | - Tkinter:Python 自带的 GUI 库
26 | - pyautogui:用于模拟键盘输入
27 | - 其他依赖项在 `requirements.txt` 中列出
28 |
29 | ## 安装与运行
30 |
31 | ### 1. 安装 Python 和依赖
32 |
33 | 确保你已经安装了 Python 3.12 或更高版本。如果尚未安装,请访问 [Python 官网](https://www.python.org/downloads/) 下载安装。
34 |
35 | 克隆此项目并安装所需的依赖:
36 |
37 | ```bash
38 | git clone <项目仓库地址>
39 | cd <项目目录>
40 | pip install -r requirements.txt
41 | ```
42 |
43 | ### 2. 安装依赖
44 | 项目的依赖项包括 `pyautogui` 和 `tkinter`。如果 `tkinter` 没有预装,可以通过以下命令安装:
45 |
46 | ```bash
47 | pip install pyautogui
48 | ```
49 |
50 | **注意**:`tkinter` 通常已经包含在标准 Python 安装中,如果遇到缺少问题,请参考 [tkinter 安装指南](https://tkdocs.com/tutorial/install.html)。
51 |
52 | ### 3. 运行程序
53 | 在安装完所有依赖后,运行以下命令启动程序:
54 |
55 | ```bash
56 | python auto_input_tool.py
57 | ```
58 |
59 | 此命令将启动图形界面,您可以在文本框中输入或粘贴文本并点击“开始输入”按钮。
60 |
61 | ### 4. 功能使用
62 | - **输入文本**:在文本框中输入或粘贴要模拟输入的文本。
63 | - **开始输入**:点击“开始输入”按钮后,程序会模拟键盘输入文本框中的内容。输入前会有 3 秒的准备时间。
64 |
65 | ## 生成 Windows 可执行文件(EXE)
66 |
67 | 如果你需要将此工具打包成独立的 Windows 可执行文件(EXE),可以使用 PyInstaller 进行打包。执行以下命令:
68 |
69 | ```bash
70 | pyinstaller --onefile --noconsole auto_input_tool.py
71 | ```
72 |
73 | 生成的 EXE 文件将位于 `dist` 目录下。
74 |
75 | ## 生成 macOS 应用(.app)
76 |
77 | 如果你在 macOS 上运行此工具,并希望打包成 macOS 应用(.app),同样可以使用 PyInstaller:
78 |
79 | ```bash
80 | pyinstaller --onefile --windowed auto_input_tool.py
81 | ```
82 |
83 | 生成的 .app 文件将位于 `dist` 目录下。
84 |
85 | ## 打包与部署
86 |
87 | 如果你希望在 GitHub Actions 上自动构建和打包 EXE 或 .app 文件,可以使用以下 `build.yml` 工作流文件:
88 |
89 | ```yaml
90 | name: Build EXE and APP
91 |
92 | on:
93 | push:
94 | branches:
95 | - main
96 | workflow_dispatch:
97 |
98 | jobs:
99 | build_windows:
100 | runs-on: windows-latest
101 | steps:
102 | - name: Checkout code
103 | uses: actions/checkout@v3
104 | - name: Set up Python
105 | uses: actions/setup-python@v4
106 | with:
107 | python-version: '3.12'
108 | - name: Install dependencies
109 | run: |
110 | python -m pip install --upgrade pip
111 | pip install -r requirements.txt
112 | - name: Install PyInstaller
113 | run: pip install pyinstaller
114 | - name: Build EXE for Windows
115 | run: pyinstaller --onefile --hidden-import pyautogui --noconsole auto_input_tool.py
116 | - name: Upload Windows EXE artifact
117 | uses: actions/upload-artifact@v3
118 | with:
119 | name: auto-input-tool-exe
120 | path: dist/auto_input_tool.exe
121 |
122 | build_macos:
123 | runs-on: macos-latest
124 | steps:
125 | - name: Checkout code
126 | uses: actions/checkout@v3
127 | - name: Set up Python
128 | uses: actions/setup-python@v4
129 | with:
130 | python-version: '3.12'
131 | - name: Install dependencies
132 | run: |
133 | python -m pip install --upgrade pip
134 | pip install -r requirements.txt
135 | - name: Install PyInstaller
136 | run: pip install pyinstaller
137 | - name: Build APP for macOS
138 | run: pyinstaller --onefile --hidden-import pyautogui --windowed auto_input_tool.py
139 | - name: Upload macOS APP artifact
140 | uses: actions/upload-artifact@v3
141 | with:
142 | name: auto-input-tool-app
143 | path: dist/auto_input_tool.app
144 | ```
145 |
146 | ## 常见问题
147 |
148 | 1. **程序未响应或输入错误**:
149 | - 确保你已正确安装 `pynput`、`pyperclip`。
150 | - 如果输入内容过长,程序可能会变慢,建议分批次输入。
151 |
152 | 2. **如何调试 PyInstaller 打包问题**:
153 | - 如果你遇到 PyInstaller 打包后的问题,可以尝试去掉 `--noconsole` 参数以查看错误日志。
154 |
155 | ## 许可证
156 | 本项目遵循 MIT 许可证。更多信息请查看 [LICENSE](./LICENSE)。
--------------------------------------------------------------------------------
/auto_input_tool.py:
--------------------------------------------------------------------------------
1 | import tkinter as tk
2 | import time
3 | import pyperclip # 用于访问剪贴板
4 | from pynput.keyboard import Controller, Key, Listener, KeyCode
5 |
6 |
7 | class AutoInputApp:
8 | def __init__(self, root):
9 | self.root = root
10 | self.root.title("自动输入工具")
11 | self.root.geometry("600x450") # 稍微增加高度以容纳新内容
12 | self.root.config(bg="#f0f0f0")
13 |
14 | # 初始化键盘控制器
15 | self.keyboard = Controller()
16 |
17 | # 热键监听状态
18 | self.ctrl_pressed = False
19 | self.shift_pressed = False
20 |
21 | # 创建键盘监听器
22 | self.listener = Listener(on_press=self.on_press, on_release=self.on_release)
23 | self.listener.start()
24 |
25 | self.label = tk.Label(root, text="自动输入工具", font=("Arial", 18, "bold"), bg="#f0f0f0", fg="#333")
26 | self.label.pack(pady=20)
27 |
28 | # 添加快捷键说明
29 | self.shortcut_label = tk.Label(root, text="快捷键: Ctrl+Shift+V - 直接从剪贴板读取并输入",
30 | font=("Arial", 12), bg="#f0f0f0", fg="#0066cc")
31 | self.shortcut_label.pack(pady=5)
32 |
33 | self.info_label = tk.Label(root, text="请在下面的文本框中输入或粘贴文本", font=("Arial", 12), bg="#f0f0f0",
34 | fg="#666")
35 | self.info_label.pack(pady=5)
36 |
37 | self.textbox = tk.Text(root, height=10, width=50, font=("Arial", 12), wrap="word", bg="#ffffff", fg="#333")
38 | self.textbox.pack(pady=10)
39 |
40 | self.input_button = tk.Button(root, text="开始输入", command=self.start_input, font=("Arial", 14), bg="#4CAF50",
41 | fg="white", relief="raised", height=2, width=20)
42 | self.input_button.pack(pady=15)
43 |
44 | self.bottom_label = tk.Label(root, text="提示:使用快捷键或文本框输入", font=("Arial", 10), bg="#f0f0f0",
45 | fg="#999")
46 | self.bottom_label.pack(pady=10)
47 |
48 | # 当窗口关闭时停止监听
49 | self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
50 |
51 | def on_press(self, key):
52 | # 检测Ctrl和Shift键是否被按下
53 | if key == Key.ctrl_l or key == Key.ctrl_r:
54 | self.ctrl_pressed = True
55 | elif key == Key.shift_l or key == Key.shift_r:
56 | self.shift_pressed = True
57 | # 检测V键并执行操作
58 | elif (key == KeyCode.from_char('v') or key == KeyCode.from_char(
59 | 'V')) and self.ctrl_pressed and self.shift_pressed:
60 | self.clipboard_input()
61 |
62 | def on_release(self, key):
63 | # 重置键的状态
64 | if key == Key.ctrl_l or key == Key.ctrl_r:
65 | self.ctrl_pressed = False
66 | elif key == Key.shift_l or key == Key.shift_r:
67 | self.shift_pressed = False
68 |
69 | def clipboard_input(self):
70 | """从剪贴板读取内容并自动输入"""
71 | try:
72 | # 获取剪贴板内容
73 | clipboard_text = pyperclip.paste()
74 | if clipboard_text:
75 | # 显示状态
76 | self.bottom_label.config(text="正在从剪贴板读取并输入...")
77 | self.root.update()
78 |
79 | # 给用户时间切换到目标窗口
80 | time.sleep(1)
81 |
82 | # 移除多余的空格
83 | clipboard_text = clipboard_text.replace(' ', '')
84 |
85 | # 逐字符输入
86 | for char in clipboard_text:
87 | self.keyboard.type(char)
88 | time.sleep(0.01) # 小延迟避免输入太快
89 |
90 | self.bottom_label.config(text="剪贴板内容输入完成!")
91 | else:
92 | self.bottom_label.config(text="剪贴板为空,没有可输入的内容!")
93 | except Exception as e:
94 | self.bottom_label.config(text=f"输入失败: {str(e)}")
95 |
96 | def start_input(self):
97 | str_in = self.textbox.get("1.0", "end-1c")
98 |
99 | if str_in:
100 | # 显示倒计时提示
101 | self.bottom_label.config(text="准备中...3秒后开始")
102 | self.root.update()
103 | time.sleep(1)
104 | self.bottom_label.config(text="准备中...2秒后开始")
105 | self.root.update()
106 | time.sleep(1)
107 | self.bottom_label.config(text="准备中...1秒后开始")
108 | self.root.update()
109 | time.sleep(1)
110 |
111 | self.bottom_label.config(text="正在输入...")
112 | self.root.update()
113 |
114 | # 移除多余的空格
115 | str_in = str_in.replace(' ', '')
116 |
117 | try:
118 | # 使用pynput逐字符输入文本
119 | for char in str_in:
120 | self.keyboard.type(char)
121 | # 可以根据需要添加小延迟,避免输入太快
122 | time.sleep(0.01)
123 |
124 | self.bottom_label.config(text="输入完成!")
125 | except Exception as e:
126 | self.bottom_label.config(text=f"输入失败: {str(e)}")
127 |
128 | def on_closing(self):
129 | """窗口关闭时的清理工作"""
130 | if self.listener:
131 | self.listener.stop()
132 | self.root.destroy()
133 |
134 |
135 | if __name__ == "__main__":
136 | root = tk.Tk()
137 | app = AutoInputApp(root)
138 | root.mainloop()
139 |
--------------------------------------------------------------------------------