发布时间:2025-06-24 19:41:50 作者:北方职教升学中心 阅读量:869
它可以根据用户设定的参数,自动进行连续的鼠标点击操作。点击频率、用户只需设置好相应的参数,按下热键即可启动连点器,实现自动化操作。连点器的工作原理是通过模拟鼠标点击动作,将用户设定的点击位置、
2.运行效果:
3.相关源码:
# -*- coding: utf8 -*-importtime,re,os,pickleimporttkinter astkfromtkinter importmessagebox,ttkimportpyautoguiimportkeyboardimportloggingimportthreading # 初始化一个空列表来保存坐标点coordinates =[]# 声明一个全局变量,用于控制循环的启动和停止is_running =Falseclick_count =0# 循环计数器clickNum =0# 标记# 设置日志记录logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(levelname)s - %(message)s')defget_mouse_position():globalclickNum x,y =pyautogui.position()coordinates.append((x,y))update_message(f"{x}, {y}\n")# 清空信息defclear():globalclick_count #清空已获取的坐标点entry1.delete(0,tk.END)entry2.delete(0,tk.END)coordinates.clear()is_running =Falseclick_count =0# 循环计数器message.config(state='normal')# 确保Text组件是可编辑的message.delete('1.0',tk.END)# 删除从第一行第一个字符到最后一个字符的所有内容message.config(state='disabled')# 清空后再次设置为禁止输入状态# 清空并删除已保存到文件里的数据messagebox.showinfo("信息","所有数据已清空")# 启动连点defstartClickThread():globalis_running,click_count seconds1 =float(entry1.get())seconds2 =float(entry2.get())whileis_running:try:# 遍历coordinates列表中的每个坐标点forx,y incoordinates:# 移动鼠标到坐标点(x, y)pyautogui.moveTo(x,y)# 模拟鼠标点击pyautogui.click()time.sleep(seconds2)# 一轮循环完成,增加计数器click_count +=1current_time =time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())update_message(f"{current_time}第 {click_count}次循环结束\n")# 等待-秒time.sleep(seconds1)exceptpyautogui.FailSafeException:update_message("操作取消,因为鼠标移动到了屏幕角落。Python 自制自动连点器
1.简介:
连点器是一种能够模拟鼠标点击操作的计算机软件,主要用于自动化和简化重复的鼠标点击任务。点击次数等参数转化为实际的鼠标点击操作。\n")is_running =FalseexceptException ase:logging.error(f"发生错误:{e}")is_running =False# 启动或停止defstartOrStop():globalis_running ifcheck_empty():# 如果两者都为空,则不执行任何操作messagebox.showwarning("警告","时间和坐标列表都不能为空!\n")returnifnotis_running:is_running =Trueupdate_message("-----启动连点,当前每 {} 秒点击一次-----\n".format(entry2.get()))threading.Thread(target=startClickThread).start()# 使用线程启动连点操作else:is_running =Falseupdate_message("-----停止连点-----\n")defcheck_empty():# 检查entry1,entry2是否为空ifentry1.get().strip()==""orentry2.get().strip()=="":returnTrueiflen(coordinates)==0:returnTruereturnFalsedefupdate_message(message_text):defsafe_update():message.config(state='normal')message.insert(tk.END,message_text)message.config(state='disabled')# 滚动到最底部message.yview(tk.END)root.after(0,safe_update)# 监听F6键keyboard.add_hotkey('f6',get_mouse_position)# 监听F7键keyboard.add_hotkey('f7',startOrStop)# 创建主窗口root =tk.Tk()# 获取屏幕宽度和高度screen_width =root.winfo_screenwidth()screen_height =root.winfo_screenheight()# 获取窗口的宽度和高度win_width =650# 假设窗口宽度为650像素win_height =400# 假设窗口高度为400像素# 计算窗口在屏幕上的位置x =(screen_width /2)-(win_width /2)y =(screen_height /2)-(win_height /2)# 设置窗口的位置root.geometry(f'{win_width}x{win_height}+{int(x)}+{int(y)}')# 获取当前脚本的绝对路径script_dir =os.path.dirname(os.path.abspath(__file__))# 构建图标文件的绝对路径icon_path =os.path.join(script_dir,'config','click.png')win_image =tk.PhotoImage(file='.\\config\\click.png')root.iconphoto(False,win_image)root.title("自动连点器")root.geometry("650x400")# 创建标签label =tk.Label(root,text="按下F6获取当前鼠标坐标")label.pack(pady=10)# 下一个大循环frame1 =tk.Frame(root)frame1.pack(fill=tk.X,expand=True)label1 =tk.Label(frame1,text="距离下一个循环点击时间:")label1.pack(side=tk.LEFT,fill=tk.X,padx=(20,10))entry1 =tk.Entry(frame1,width=10)entry1.pack(side=tk.LEFT,fill=tk.X,expand=True)label2 =tk.Label(frame1,text="s/秒")label2.pack(side=tk.LEFT,fill=tk.X,padx=(20,10))# 下一次点击frame2 =tk.Frame(root)frame2.pack(fill=tk.X,expand=True)label3 =tk.Label(frame2,text="距离下一个点击时间:")label3.pack(side=tk.LEFT,fill=tk.X,padx=(20,10))entry2 =tk.Entry(frame2,width=10)entry2.pack(side=tk.LEFT,fill=tk.X,expand=True)label4 =tk.Label(frame2,text="s/秒")label4.pack(side=tk.LEFT,fill=tk.X,padx=(20,10))# 创建按钮frame5 =tk.Frame(root)frame5.pack(fill=tk.X,expand=True)button1 =tk.Button(frame5,text="清空",command=clear)button1.pack(side=tk.LEFT,fill=tk.X,expand=True)button2 =tk.Button(frame5,text="启动/停止(F7)",command=startOrStop)button2.pack(side=tk.LEFT,fill=tk.X,expand=True)# 创建一个Label用于显示信息message =tk.Text(root,state='disabled')message.pack(fill=tk.BOTH,expand=True,padx=5,pady=5)# 运行主循环root.mainloop()keyboard.wait()