【教程】按键精灵连点器 之 咸鱼之王

2023-06-13 16:13:22 浏览数 (1)


Python版

需要用到的库:

pip install pynput pyautoit

代码语言:javascript复制
import tkinter as tk
from tkinter import ttk
import time
import autoit
import threading
from tkinter import messagebox
from pynput import keyboard
import sys
 
# 增大迭代限制
sys.setrecursionlimit(1000000000)
 
class App:
    def __init__(self, master):
        self.master = master
        master.title("简易连点器-小锋学长生活大爆炸(ESC键停止)")
        # 设置连点的时间间隔,单位为毫秒
        self.interval = 0.5
        # 连点计数器
        self.click_count = 0
        self.click_total = 10
        # 创建输入框
        self.x_label = tk.Label(master, text="X坐标:", width=15)
        self.x_label.grid(row=0, column=0, padx=5, pady=10)
        self.x_entry = tk.Entry(master, width=10)
        self.x_entry.insert(tk.END, "100")
        self.x_entry.grid(row=0, column=1, padx=5, pady=10)
        self.y_label = tk.Label(master, text="Y坐标:", width=15)
        self.y_label.grid(row=1, column=0, padx=5, pady=10)
        self.y_entry = tk.Entry(master, width=10)
        self.y_entry.insert(tk.END, "100")
        self.y_entry.grid(row=1, column=1, padx=5, pady=10)
        # 增加self.click_total的输入框
        self.total_label = tk.Label(master, text="点击总数(0为无限):", width=15)
        self.total_label.grid(row=2, column=0, padx=5, pady=10)
        self.total_entry = tk.Entry(master, width=10)
        self.total_entry.insert(tk.END, "10")
        self.total_entry.grid(row=2, column=1, padx=5, pady=10)
        # 增加self.interval的输入框
        self.interval_label = tk.Label(master, text="点击间隔(ms):", width=15)
        self.interval_label.grid(row=3, column=0, padx=5, pady=10)
        self.interval_entry = tk.Entry(master, width=10)
        self.interval_entry.insert(tk.END, "500")
        self.interval_entry.grid(row=3, column=1, padx=5, pady=10)
        # 创建进度条和标签
        self.progress_bar = ttk.Progressbar(master, orient="horizontal", mode="determinate")
        self.progress_bar.grid(row=4, column=0, padx=5, pady=10)
        self.progress_label = tk.Label(master, text="0 / {}".format(self.click_total), width=5)
        self.progress_label.grid(row=4, column=1, padx=5, pady=10)
        # 创建启动和停止按钮
        self.start_button = tk.Button(master, text="启动", command=self.start_click, width=5)
        self.start_button.grid(row=5, column=0, padx=5, pady=10)
        self.stop_button = tk.Button(master, text="停止", command=self.stop_click, width=5)
        self.stop_button.grid(row=5, column=1, padx=5, pady=10)
         
        # 创建一个标志,表示是否按下了ESC键
        self.esc_pressed = False
    def start_click(self):
        # 启动连点器
        self.x = int(self.x_entry.get())
        self.y = int(self.y_entry.get())
        self.click_count = 0
        self.running = True
        self.click_total = int(self.total_entry.get()) or 1e9
        self.interval = int(self.interval_entry.get()) / 1000
        self.progress_bar["maximum"] = self.click_total
        self.progress_bar["value"] = 0
         # 创建一个子线程,用于监听键盘是否按下ESC键
        self.listener_thread = threading.Thread(target=self.listener_start)
        self.listener_thread.start()
        while self.running and self.click_count < self.click_total:
            self.click_count  = 1
            # 鼠标左键点击
            autoit.mouse_click("left", self.x, self.y)
            # 等待interval毫秒
            time.sleep(self.interval)
            # 更新进度条和标签
            self.progress_bar["value"] = self.click_count
            self.progress_label["text"] = "{} / {}".format(self.click_count, self.click_total)
            self.master.update()
             # 如果按下了ESC键,则停止连点器
            if self.esc_pressed:
                self.stop_click()
                break
        # 点击结束后,停止子线程
        self.listener_thread.join()
        messagebox.showinfo("提示", "连点器已停止")
    def stop_click(self):
        # 停止连点器
        self.running = False
        self.esc_pressed = False
    def listener_on_press(self, key):
        try:
            if key.char == keyboard.Key.esc:
                print("ESC is pressed")
        except AttributeError:
            pass
    def listener_on_release(self, key):
        if key == keyboard.Key.esc:
            return False
    def listener_start(self):
        # 监听键盘是否按下ESC键
        while self.running:
            # 启动键盘监听器
            with keyboard.Listener(on_press=self.listener_on_press, on_release=self.listener_on_release) as listener:
                listener.join()
                self.esc_pressed = True
                break
root = tk.Tk()
app = App(root)
# 设置窗口置顶
root.wm_attributes("-topmost", True)
root.mainloop()

按键精灵版

代码语言:javascript复制
/*
	API指南:https://zimaoxy.com/q/categories/02-基本命令/
*/

// 坐标定义区
top_left_x = 1470  // 窗口左上角x坐标,不包括标题栏,只需要修改这两个
top_left_y = 43// 窗口左上角y坐标,不包括标题栏,只需要修改这两个



win_width = 450    // 窗口宽度
win_height = 800   // 窗口高度

// 点击位置
click_x = top_left_x   win_width/2    // 1625
click_y = top_left_y   win_height/3*2 // 703

// 战斗按钮的点击/找色位置
btn_fight_w = 100
btn_fight_h = 80
btn_fight_tx = top_left_x   win_width/2 - btn_fight_w/2  // 左上角
btn_fight_ty = top_left_y   win_height - btn_fight_h     // 左上角
btn_fight_cx = btn_fight_tx   btn_fight_w/2  // 中心
btn_fight_cy = btn_fight_ty   btn_fight_h/2   // 中心


// 其他变量定义区
esc_key_code = 27  // ESC按键编号
btn_fight_active_color = "234B75"
club_msgbox_color = "12110F"



// 函数定义区
Function ClickAtFightBtn()
	MoveTo btn_fight_cx, btn_fight_cy
	Delay 10
	LeftClick 1
End Function

Function ClickAtClicArea()
	MoveTo click_x, click_y
	Delay 100
	LeftClick 1
	Delay 100
End Function


// 移动到战斗位置
Call ClickAtFightBtn()

cnt = 0
// 开始点击
Do While 1
	cnt = cnt   1
	If cnt = 10000 Then 
		cnt = 0
		Call ClickAtFightBtn()
	End If


	// 判断是否按下esc键导致终止
	last_key = GetLastKey()   
	If last_key=esc_key_code Then  
    	Exit Do
	End If
	
	// 判断鼠标是否被移动
	GetCursorPos x, y
	If x <> click_x And y <> click_y Then
    	Call ClickAtClicArea()
	End If
	
	
	
	
	LeftClick 1
	Delay 10

Loop

Sub OnScriptExit()
    MessageBox "脚本已经停止!"
End Sub

0 人点赞