吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4159|回复: 90
收起左侧

[Python 原创] python自制windows的定时鼠标点击器,到点模拟鼠标点击

  [复制链接]
canso123 发表于 2024-7-12 16:05
本帖最后由 canso123 于 2024-7-18 19:23 编辑

[Python] 纯文本查看 复制代码
#!/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'))[0:10]
    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'))[0:10]
    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(',')[0])
            y3 = int(entry3.get().split(',')[1])
            pyautogui.click(x3, y3)

        if entry5.get() == '' and entry6.get() == '' and entry3.get() != '' and entry4.get() != '':
            x3 = int(entry3.get().split(',')[0])
            y3 = int(entry3.get().split(',')[1])
            x4 = int(entry4.get().split(',')[0])
            y4 = int(entry4.get().split(',')[1])
            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(',')[0])
            y3 = int(entry3.get().split(',')[1])
            x4 = int(entry4.get().split(',')[0])
            y4 = int(entry4.get().split(',')[1])
            x5 = int(entry5.get().split(',')[0])
            y5 = int(entry5.get().split(',')[1])
            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(',')[0])
            y3 = int(entry3.get().split(',')[1])
            x4 = int(entry4.get().split(',')[0])
            y4 = int(entry4.get().split(',')[1])
            x5 = int(entry5.get().split(',')[0])
            y5 = int(entry5.get().split(',')[1])
            x6 = int(entry6.get().split(',')[0])
            y6 = int(entry6.get().split(',')[1])
            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

运行截图

运行截图

免费评分

参与人数 15吾爱币 +19 热心值 +13 收起 理由
15871246850 + 1 + 1 谢谢@Thanks!
vicmay + 1 + 1 我很赞同!
Myli123 + 1 我很赞同!
Mfjhkj + 1 我很赞同!
Tking#5366 + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
大大连连 + 1 + 1 谢谢@Thanks!
quax + 1 我很赞同!
fancw17 + 1 + 1 我很赞同!
macolma + 1 谢谢@Thanks!
WXJYXLWMH + 1 + 1 谢谢@Thanks!
shanzhanzhe + 1 + 1 谢谢@Thanks!
kkpljat + 1 + 1 谢谢@Thanks!
Arcticlyc + 1 + 1 代码没编辑好
ttxs1234 + 1 + 1 鼓励转贴优秀软件安全工具和文档!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

omar111 发表于 2024-9-22 17:17
增加了每个坐标可以单独设置延迟时间
[Python] 纯文本查看 复制代码
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 = [tk.StringVar() for _ in range(4)]

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'))[0:10]
    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'))[0:10]
    print(a1)
    b = str(entry1.get())
    if not running:
        return
    if a1 == b:
        print("时间到了,抢购")
    num = 0
    while a1 == b and running:
        delays = [int(delay_vars[i].get()) if delay_vars[i].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[0] / 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[0] / 1000)
            pyautogui.click(x4, y4)
            pyautogui.sleep(delays[1] / 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[0] / 1000)
            pyautogui.click(x4, y4)
            pyautogui.sleep(delays[1] / 1000)
            pyautogui.click(x5, y5)
            pyautogui.sleep(delays[2] / 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[0] / 1000)
            pyautogui.click(x4, y4)
            pyautogui.sleep(delays[1] / 1000)
            pyautogui.click(x5, y5)
            pyautogui.sleep(delays[2] / 1000)
            pyautogui.click(x6, y6)
            pyautogui.sleep(delays[3] / 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[0], 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[1], 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[2], 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[3], 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()
yutenys 发表于 2024-7-13 17:30
b1uecream 发表于 2024-7-12 16:32
先把代码拿来跑一下。
给个建议,做个requments.txt说明一下对python模块的依赖情况。

一共4个依赖库,tkinter和datetime都是Python自带的
pyautogui和keyboard 直接pip install 就行了
 楼主| canso123 发表于 2024-7-15 02:21
ying656 发表于 2024-7-12 17:53
一直想学习此类编程,但是想用的方法是找到windows中的控件。尤其是各种程序好像API
那样准确控制。但是就 ...

我没有哦,兄台。我也是初学者
 楼主| canso123 发表于 2024-7-12 16:06
额。这个程序源码是不是要贴到哪里,还不怎么会,。。。。版主给我编辑一下?
b1uecream 发表于 2024-7-12 16:32
先把代码拿来跑一下。
给个建议,做个requments.txt说明一下对python模块的依赖情况。

免费评分

参与人数 1吾爱币 +1 收起 理由
Arcticlyc + 1 我很赞同!

查看全部评分

gtfbhfe 发表于 2024-7-12 16:45
是个很好的工具,感觉用来刷视频可行
Tking#5366 发表于 2024-7-12 17:26
这个还需要python环境才能运行啊,能打包成exe么?
wasm2023 发表于 2024-7-12 17:33
请问楼主,支持后台吗
zhufuan 发表于 2024-7-12 17:39
老师,这个有exe可执行文件吗吗
ying656 发表于 2024-7-12 17:53
一直想学习此类编程,但是想用的方法是找到windows中的控件。尤其是各种程序好像API
那样准确控制。但是就是一直没找到如何可以准确判断控件位置,和如何智能判断控件类型并点击的程序 自己写起来确实比较费力。请问兄台那里有类似源码么
9382968 发表于 2024-7-12 17:56
简单明了,挺好
houwangchao 发表于 2024-7-12 19:37
刷视频应该很好用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 11:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表