彩笔写的丐版Python连点器
良性bug没有解决:线程没法单独终止,而是直接终止了所有线程。
源代码
import pyautogui import time from pynput.keyboard import Key, Listener import threading click = int(input("请输入点击次数:")) m = float(input("请输入点击间隔(秒):")) print("1.鼠标放在合适位置,按j记录坐标") print("2.按k运行连点器") print("3.按t可以结束程序") x = 0 y = 0 threads = [] positions = [] def click_it(x, y, c, m): for i in range(c): pyautogui.click(x, y) time.sleep(m) def on_press(key): global x, y, user_input if hasattr(key, 'char'): if key.char == 'j': # 按j检测位置 x, y = pyautogui.position() positions.append((x, y)) # 元组形式存入列表 print(f"x:{x} y:{y}") elif key.char == 'k': # 按k启动一个连点线程 global click, m t1 = threading.Thread(target=click_it, args=(*positions[-1], click, m)) # *是解包的意思 threads.append(t1) t1.start() elif key.char == 't': # 按t终止程序 listener.stop() # 创建监听器对象并开始监听按键 listener = Listener(on_press=on_press) listener.start() # 等待用户输入t使监听器停止 while listener.is_alive(): time.sleep(1) # 关闭监听器和用户输入线程 listener.stop() print("程序结束")
pyinstaller打包方法
pip install pyinstallerpip show pyautogui,如果没有模块就pip install pyautoguipip show pynput,如果没有模块就pip install pynputpyinstaller注意不要有-w- 到/dist文件下找到main.exe运行