python连点器

大家都在用连点器,所以用python写了一个连点器,可以支持鼠标和键盘混合连点。

我用Python编写一个GUI页面,让用户可以自由定义键盘按键和鼠标连点的连点器,并通过按下键盘上的M键来开启或关闭连点器。为此,我们需要使用Python的GUI库tkinter来创建GUI页面。

以下是使用界面,效果良好,功能比得上一些连点器。

python连点器_第1张图片

下面是一个简单的Python程序,它包含一个GUI窗口和一些控件,用于让用户定义鼠标点击和键盘按键的连点器,以及通过按下M键来开启或关闭连点器:

import tkinter as tk
import time
import threading
import pyautogui as pag
import keyboard

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()
        self.master.geometry('500x310')
        self.is_running = False  # 添加 is_running 属性

    def create_widgets(self):
        self.status_label = tk.Label(self, text="连点器已关闭", fg="red")
        self.status_label.pack()

        self.mouse_button_label = tk.Label(self, text="鼠标键:")
        self.mouse_button_label.pack()
        self.mouse_button_var = tk.StringVar()
        self.mouse_button_var.set("left")
        self.mouse_button_optionmenu = tk.OptionMenu(self, self.mouse_button_var, "left", "right")
        self.mouse_button_optionmenu.pack()

        self.interval_label = tk.Label(self, text="间隔时间(毫秒):")
        self.interval_label.pack()
        self.interval_entry = tk.Entry(self)
        self.interval_entry.pack()

        self.move_mouse_var = tk.BooleanVar()
        self.move_mouse_var.set(False)
        self.move_mouse_checkbox = tk.Checkbutton(self, text="移动鼠标", variable=self.move_mouse_var)
        self.move_mouse_checkbox.pack()

        self.move_pixel_label = tk.Label(self, text="移动像素数:")
        self.move_pixel_label.pack()
        self.move_pixel_entry = tk.Entry(self)
        self.move_pixel_entry.pack()

        self.keyboard_label = tk.Label(self, text="键盘按键:")
        self.keyboard_label.pack()
        self.keyboard_entry = tk.Entry(self)
        self.keyboard_entry.pack()

        self.start_button = tk.Button(self, text="开始", command=self.start_clicker)
        self.start_button.pack()

        self.stop_button = tk.Button(self, text="停止", command=self.stop_clicker, state="disabled")
        self.stop_button.pack()

        # 监听键盘事件
        keyboard.on_press_key("m", self.toggle_clicker)

    def toggle_clicker(self, event):
        if self.is_running:
            self.stop_clicker()
        else:
            self.start_clicker()

    def start_clicker(self):
        self.is_running = True
        self.status_label.config(text="正在连点中", fg="green")
        self.start_button.config(state="disabled")
        self.stop_button.config(state="normal")

        button = self.mouse_button_var.get()
        interval = int(self.interval_entry.get()) / 1000
        move_mouse = self.move_mouse_var.get()
        move_pixel = int(self.move_pixel_entry.get())
        keyboard_key = self.keyboard_entry.get()

        self.clicker_thread = threading.Thread(target=self.do_clicking,
                                               args=(button, interval, move_mouse, move_pixel, keyboard_key))
        self.clicker_thread.start()

    def do_clicking(self, button, interval, move_mouse, move_pixel, keyboard_key):
        while self.is_running:
            if move_mouse:
                pag.moveRel(0, move_pixel)
            pag.click(button=button)
            if keyboard_key:
                keyboard.press(keyboard_key)
                keyboard.release(keyboard_key)
            time.sleep(interval)

    def stop_clicker(self):
        self.is_running = False
        self.status_label.config(text="连点器已关闭", fg="red")
        self.start_button.config(state="normal")
        self.stop_button.config(state="disabled")


if __name__ == "__main__":
    root = tk.Tk()
    app = Application(master=root)
    app.mainloop()

在这个程序中,我们创建了一个名为的类,它继承自tkinter的类。在类方法中,我们创建了GUI窗口,并在窗口中添加了一些控件,例如标签、输入框、复选框、下拉菜单和按钮等。这些控件用于让用户输入需要的设置,例如连点次数、鼠标键、间隔时间、移动鼠标、移动像素数和键盘按键等。ApplicationFrameApplication__init__

在类中,我们还定义了方法和方法,用于启动和停止连点器。当用户点击“开始”按钮时,程序会读取用户输入的设置,并创建一个新的线程来模拟鼠标点击和键盘按键。线程中的方法会根据用户的设置,循环执行鼠标点击和键盘按键的操作,直到达到设定的连点次数。当用户点击“停止”按钮时,程序会停止当前正在运行的线程,并关闭连点器。Applicationstart_clickerstop_clickerdo_clicking

在类中,我们还定义了一个方法,用于处理用户按下键盘上的M键的事件。当用户按下M键时,程序会判断当前是否有连点器正在运行。如果没有,则启动连点器;如果有,则停止连点器。Applicationon_key_press

最后,在程序的主函数中,我们创建了一个对象,并通过方法让程序进入事件循环,等待用户的输入和操作。当用户关闭窗口时,程序会退出。Applicationmainloop

注意:需要安装keyboardpyautogui库,这两个库用于监听键盘和鼠标事件以及模拟键盘和鼠标操作。您可以使用以下命令来安装这两个库:

pip install keyboard
pip install pyautogui

如果您的电脑上没有安装pip,您需要先安装pip。在Windows上,您可以在命令提示符或PowerShell中运行以下命令:

python -m ensurepip --default-pip

新手制作,请大佬多提建议,谢谢!

你可能感兴趣的:(python)