python自制windows的定时鼠标点击器,到点模拟鼠标点击
本帖最后由 canso123 于 2024-7-18 19:23 编辑#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
版本更新,可以在点击esc按键,停止程序
修改时间可以点击再次运行
"""
import tkinter as tk
import pyautogui
import datetime
import keyboard
from tkinter import ttk
# pyautogui.PAUSE=0.1
# 添加一个全局变量作为停止标志
running = True
root_window = tk.Tk()# 建立窗口
root_window.resizable(0, 0)# 设置窗口不可改变大小
root_window.title("定时点击器——吾爱破解论坛-canso123")# 设置窗口标题
kuan = root_window.winfo_screenwidth()# 获取电脑屏幕尺寸:宽
gao = root_window.winfo_screenheight()# 获取电脑屏幕尺寸:高
root_window.geometry(f"900x800+{kuan // 3}+{gao // 12}")# 按照电脑显示设置窗口大小
root_window["background"] = 'light green'# 设置窗口背景色
var0 = tk.StringVar()# 系统时间
var1 = tk.StringVar()# 设定时间
var2 = tk.StringVar()# 点击次数
var3 = tk.StringVar()# 坐标1
var4 = tk.StringVar()# 坐标2
var5 = tk.StringVar()# 坐标3
var6 = tk.StringVar()# 坐标4
var7 = tk.StringVar()# 坐标显示
# 在定义变量处添加一个新的变量用于存储checkbutton的状态
show_coordinates = tk.BooleanVar()
def on_stop_key_pressed(e):
global running
if e.name == 'esc':# 当用户按下ESC键时停止
running = False
keyboard.on_press(on_stop_key_pressed)
def ShuaXin():
a = str(datetime.datetime.now().strftime('%H:%M:%S:%f'))
var0.set(a)
if show_coordinates.get():# 如果checkbutton被选中,则显示鼠标坐标
xy = pyautogui.position()
var7.set(str(xy))
else:
var7.set("")# 如果未选中,则清空坐标显示
root_window.after(100, ShuaXin)
ShuaXin()
def DianJi():
global running
running = True
a1 = str(datetime.datetime.now().strftime('%H:%M:%S:%f'))
print(a1)
b = str(entry1.get())
if not running:
return
if a1 == b:
print("时间到了,抢购")
num = 0
while a1 == b and running:
if entry4.get() == '' and entry5.get() == '' and entry6.get() == '' and entry3.get() != '':
x3 = int(entry3.get().split(','))
y3 = int(entry3.get().split(','))
pyautogui.click(x3, y3)
if entry5.get() == '' and entry6.get() == '' and entry3.get() != '' and entry4.get() != '':
x3 = int(entry3.get().split(','))
y3 = int(entry3.get().split(','))
x4 = int(entry4.get().split(','))
y4 = int(entry4.get().split(','))
pyautogui.click(x3, y3)
pyautogui.click(x4, y4)
if entry6.get() == '' and entry3.get() != '' and entry4.get() != '' and entry5.get() != '':
x3 = int(entry3.get().split(','))
y3 = int(entry3.get().split(','))
x4 = int(entry4.get().split(','))
y4 = int(entry4.get().split(','))
x5 = int(entry5.get().split(','))
y5 = int(entry5.get().split(','))
pyautogui.click(x3, y3)
pyautogui.click(x4, y4)
pyautogui.click(x5, y5)
if entry3.get() != '' and entry4.get() != '' and entry5.get() != '' and entry6.get() != '':
x3 = int(entry3.get().split(','))
y3 = int(entry3.get().split(','))
x4 = int(entry4.get().split(','))
y4 = int(entry4.get().split(','))
x5 = int(entry5.get().split(','))
y5 = int(entry5.get().split(','))
x6 = int(entry6.get().split(','))
y6 = int(entry6.get().split(','))
pyautogui.click(x3, y3)
pyautogui.click(x4, y4)
pyautogui.click(x5, y5)
pyautogui.click(x6, y6)
num += 1
if num == int(entry2.get()) or not running:
# os.system("shutdown -h")
break
root_window.after(100, DianJi)
LB0 = tk.Label(root_window, text="系统时间:", font=("宋体", 16), relief='groove', background='yellow')
LB0.grid(row=0, column=0, padx=10, pady=10)
entry0 = tk.Entry(root_window, textvariable=var0, font=("宋体", 22))
# entry0.config(justify='center')
entry0.grid(row=0, column=2, padx=10, pady=10)
LB1 = tk.Label(root_window, text="点击时间:", font=("宋体", 16), relief='groove', background='aqua')
LB1.grid(row=1, column=0, padx=10, pady=10)
entry1 = tk.Entry(root_window, textvariable=var1, font=("宋体", 22))
entry1.grid(row=1, column=2, padx=10, pady=10)
LB2 = tk.Label(root_window, text="点击次数:", font=("宋体", 16), relief='groove', background='orchid')
LB2.grid(row=2, column=0, sticky="w", padx=10, pady=15)
entry2 = tk.Entry(root_window, textvariable=var2, font=("宋体", 22))
entry2.grid(row=2, column=2)
LB3 = tk.Label(root_window, text="坐标1:", font=("宋体", 16), relief='groove', background='wheat')
LB3.grid(row=3, column=0, sticky="w", padx=10, pady=15)
entry3 = tk.Entry(root_window, textvariable=var3, font=("宋体", 22))
entry3.grid(row=3, column=2)
LB4 = tk.Label(root_window, text="坐标2:", font=("宋体", 16), relief='groove', background='wheat')
LB4.grid(row=4, column=0, sticky="w", padx=10, pady=15)
entry4 = tk.Entry(root_window, textvariable=var4, font=("宋体", 22))
entry4.grid(row=4, column=2)
LB5 = tk.Label(root_window, text="坐标3:", font=("宋体", 16), relief='groove', background='wheat')
LB5.grid(row=5, column=0, sticky="w", padx=10, pady=15)
entry5 = tk.Entry(root_window, textvariable=var5, font=("宋体", 22))
entry5.grid(row=5, column=2)
LB6 = tk.Label(root_window, text="坐标4:", font=("宋体", 16), relief='groove', background='wheat')
LB6.grid(row=6, column=0, sticky="w", padx=10, pady=15)
entry6 = tk.Entry(root_window, textvariable=var6, font=("宋体", 22))
entry6.grid(row=6, column=2)
BT = tk.Button(root_window, text="点击开始", font=("宋体", 16), width=14, height=2, relief='groove', command=DianJi,
background='green')
BT.place(x=640, y=650, width=200, height=80)
entry7 = tk.Entry(root_window, textvariable=var7, font=("宋体", 20))
entry7.place(x=10, y=650, width=600, height=80)
style = ttk.Style()
# 配置Checkbutton的样式
style.configure('TCheckbutton', background='wheat', font=("宋体", 16), relief='groove')# 将背景颜色设置
# 设置变量
show_coordinates = tk.BooleanVar()
# 在GUI布局部分添加一个Checkbutton
CB_show_coordinates = ttk.Checkbutton(root_window, text="实时坐标", variable=show_coordinates, style='TCheckbutton')
CB_show_coordinates.grid(row=7, column=0, sticky="w", padx=10, pady=15)
root_window.mainloop()
以上就是程序源码啦。
附上程序运行的照片
可以设置点击时间,点击坐标最下面是实时的坐标,中间坐标设计几个就点击几个。
运行过程中可以点击ESC取消点击,可以勾选是否显示当前实时坐标
有小伙伴说要成品的exe打包的,我这就给你们打包了哈,压缩包,解压即可
123网盘地址 https://www.123pan.com/s/lmcMjv-4oEuA.html
增加了每个坐标可以单独设置延迟时间
import tkinter as tk
import pyautogui
import datetime
import keyboard
from tkinter import ttk
# 添加一个全局变量作为停止标志
running = True
root_window = tk.Tk()
root_window.resizable(0, 0)
root_window.title("定时点击器——吾爱破解论坛-canso123")
kuan = root_window.winfo_screenwidth()
gao = root_window.winfo_screenheight()
root_window.geometry(f"900x800+{kuan // 3}+{gao // 12}")
root_window["background"] = 'light green'
var0 = tk.StringVar()
var1 = tk.StringVar()
var2 = tk.StringVar()
var3 = tk.StringVar()
var4 = tk.StringVar()
var5 = tk.StringVar()
var6 = tk.StringVar()
var7 = tk.StringVar()
# 用于存储 checkbutton 的状态
show_coordinates = tk.BooleanVar()
# 用于存储每个坐标的延迟时间
delay_vars =
def on_stop_key_pressed(e):
global running
if e.name == 'esc':
running = False
keyboard.on_press(on_stop_key_pressed)
def ShuaXin():
a = str(datetime.datetime.now().strftime('%H:%M:%S:%f'))
var0.set(a)
if show_coordinates.get():
xy = pyautogui.position()
var7.set(str(xy))
else:
var7.set("")
root_window.after(100, ShuaXin)
ShuaXin()
def DianJi():
global running
running = True
a1 = str(datetime.datetime.now().strftime('%H:%M:%S:%f'))
print(a1)
b = str(entry1.get())
if not running:
return
if a1 == b:
print("时间到了,抢购")
num = 0
while a1 == b and running:
delays = .get()) if delay_vars.get() else 0 for i in range(4)]
if entry4.get() == '' and entry5.get() == '' and entry6.get() == '' and entry3.get()!= '':
x3, y3 = map(int, entry3.get().split(','))
pyautogui.click(x3, y3)
pyautogui.sleep(delays / 1000)
if entry5.get() == '' and entry6.get() == '' and entry3.get()!= '' and entry4.get()!= '':
x3, y3 = map(int, entry3.get().split(','))
x4, y4 = map(int, entry4.get().split(','))
pyautogui.click(x3, y3)
pyautogui.sleep(delays / 1000)
pyautogui.click(x4, y4)
pyautogui.sleep(delays / 1000)
if entry6.get() == '' and entry3.get()!= '' and entry4.get()!= '' and entry5.get()!= '':
x3, y3 = map(int, entry3.get().split(','))
x4, y4 = map(int, entry4.get().split(','))
x5, y5 = map(int, entry5.get().split(','))
pyautogui.click(x3, y3)
pyautogui.sleep(delays / 1000)
pyautogui.click(x4, y4)
pyautogui.sleep(delays / 1000)
pyautogui.click(x5, y5)
pyautogui.sleep(delays / 1000)
if entry3.get()!= '' and entry4.get()!= '' and entry5.get()!= '' and entry6.get()!= '':
x3, y3 = map(int, entry3.get().split(','))
x4, y4 = map(int, entry4.get().split(','))
x5, y5 = map(int, entry5.get().split(','))
x6, y6 = map(int, entry6.get().split(','))
pyautogui.click(x3, y3)
pyautogui.sleep(delays / 1000)
pyautogui.click(x4, y4)
pyautogui.sleep(delays / 1000)
pyautogui.click(x5, y5)
pyautogui.sleep(delays / 1000)
pyautogui.click(x6, y6)
pyautogui.sleep(delays / 1000)
num += 1
if num == int(entry2.get()) or not running:
# os.system("shutdown -h")
break
root_window.after(100, DianJi)
LB0 = tk.Label(root_window, text="系统时间:", font=("宋体", 16), relief='groove', background='yellow')
LB0.grid(row=0, column=0, padx=10, pady=10)
entry0 = tk.Entry(root_window, textvariable=var0, font=("宋体", 22))
entry0.grid(row=0, column=2, padx=10, pady=10)
LB1 = tk.Label(root_window, text="点击时间:", font=("宋体", 16), relief='groove', background='aqua')
LB1.grid(row=1, column=0, padx=10, pady=10)
entry1 = tk.Entry(root_window, textvariable=var1, font=("宋体", 22))
entry1.grid(row=1, column=2, padx=10, pady=10)
LB2 = tk.Label(root_window, text="点击次数:", font=("宋体", 16), relief='groove', background='orchid')
LB2.grid(row=2, column=0, sticky="w", padx=10, pady=15)
entry2 = tk.Entry(root_window, textvariable=var2, font=("宋体", 22))
entry2.grid(row=2, column=2)
LB3 = tk.Label(root_window, text="坐标1:", font=("宋体", 16), relief='groove', background='wheat')
LB3.grid(row=3, column=0, sticky="w", padx=10, pady=15)
entry3 = tk.Entry(root_window, textvariable=var3, font=("宋体", 22))
entry3.grid(row=3, column=2)
delay_label3 = tk.Label(root_window, text="延迟1(毫秒):", font=("宋体", 16), relief='groove', background='wheat')
delay_label3.grid(row=3, column=3, sticky="w", padx=10, pady=15)
delay_entry3 = tk.Entry(root_window, textvariable=delay_vars, font=("宋体", 22))
delay_entry3.grid(row=3, column=4)
LB4 = tk.Label(root_window, text="坐标2:", font=("宋体", 16), relief='groove', background='wheat')
LB4.grid(row=4, column=0, sticky="w", padx=10, pady=15)
entry4 = tk.Entry(root_window, textvariable=var4, font=("宋体", 22))
entry4.grid(row=4, column=2)
delay_label4 = tk.Label(root_window, text="延迟2(毫秒):", font=("宋体", 16), relief='groove', background='wheat')
delay_label4.grid(row=4, column=3, sticky="w", padx=10, pady=15)
delay_entry4 = tk.Entry(root_window, textvariable=delay_vars, font=("宋体", 22))
delay_entry4.grid(row=4, column=4)
LB5 = tk.Label(root_window, text="坐标3:", font=("宋体", 16), relief='groove', background='wheat')
LB5.grid(row=5, column=0, sticky="w", padx=10, pady=15)
entry5 = tk.Entry(root_window, textvariable=var5, font=("宋体", 22))
entry5.grid(row=5, column=2)
delay_label5 = tk.Label(root_window, text="延迟3(毫秒):", font=("宋体", 16), relief='groove', background='wheat')
delay_label5.grid(row=5, column=3, sticky="w", padx=10, pady=15)
delay_entry5 = tk.Entry(root_window, textvariable=delay_vars, font=("宋体", 22))
delay_entry5.grid(row=5, column=4)
LB6 = tk.Label(root_window, text="坐标4:", font=("宋体", 16), relief='groove', background='wheat')
LB6.grid(row=6, column=0, sticky="w", padx=10, pady=15)
entry6 = tk.Entry(root_window, textvariable=var6, font=("宋体", 22))
entry6.grid(row=6, column=2)
delay_label6 = tk.Label(root_window, text="延迟4(毫秒):", font=("宋体", 16), relief='groove', background='wheat')
delay_label6.grid(row=6, column=3, sticky="w", padx=10, pady=15)
delay_entry6 = tk.Entry(root_window, textvariable=delay_vars, font=("宋体", 22))
delay_entry6.grid(row=6, column=4)
BT = tk.Button(root_window, text="点击开始", font=("宋体", 16), width=14, height=2, relief='groove', command=DianJi,
background='green')
BT.place(x=640, y=650, width=200, height=80)
entry7 = tk.Entry(root_window, textvariable=var7, font=("宋体", 20))
entry7.place(x=10, y=650, width=600, height=80)
style = ttk.Style()
# 配置 Checkbutton 的样式
style.configure('TCheckbutton', background='wheat', font=("宋体", 16), relief='groove')
# 设置变量
show_coordinates = tk.BooleanVar()
# 在 GUI 布局部分添加一个 Checkbutton
CB_show_coordinates = ttk.Checkbutton(root_window, text="实时坐标", variable=show_coordinates, style='TCheckbutton')
CB_show_coordinates.grid(row=7, column=0, sticky="w", padx=10, pady=15)
root_window.mainloop() b1uecream 发表于 2024-7-12 16:32
先把代码拿来跑一下。
给个建议,做个requments.txt说明一下对python模块的依赖情况。
一共4个依赖库,tkinter和datetime都是Python自带的
pyautogui和keyboard 直接pip install 就行了 ying656 发表于 2024-7-12 17:53
一直想学习此类编程,但是想用的方法是找到windows中的控件。尤其是各种程序好像API
那样准确控制。但是就 ...
我没有哦,兄台。我也是初学者 额。这个程序源码是不是要贴到哪里,还不怎么会,。。。。版主给我编辑一下?{:1_893:} 先把代码拿来跑一下。
给个建议,做个requments.txt说明一下对python模块的依赖情况。 是个很好的工具,感觉用来刷视频可行 这个还需要python环境才能运行啊,能打包成exe么?
请问楼主,支持后台吗 老师,这个有exe可执行文件吗吗 一直想学习此类编程,但是想用的方法是找到windows中的控件。尤其是各种程序好像API
那样准确控制。但是就是一直没找到如何可以准确判断控件位置,和如何智能判断控件类型并点击的程序 自己写起来确实比较费力。请问兄台那里有类似源码么 简单明了,挺好 刷视频应该很好用