first commit
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import os
|
||||
import pyautogui
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
import time
|
||||
|
||||
|
||||
class AutoClicker:
|
||||
def __init__(self, src_folder="src"):
|
||||
self.src_folder = src_folder
|
||||
self.png_files = []
|
||||
|
||||
def load_png_list(self):
|
||||
"""加载src文件夹中的所有PNG文件"""
|
||||
if not os.path.exists(self.src_folder):
|
||||
os.makedirs(self.src_folder)
|
||||
print(f"文件夹 {self.src_folder} 不存在,已创建。")
|
||||
return []
|
||||
|
||||
self.png_files = [f for f in os.listdir(self.src_folder) if f.endswith(".png")]
|
||||
print(f"加载PNG文件列表: {self.png_files}")
|
||||
return self.png_files
|
||||
|
||||
def check_image_on_screen(self, image_path, confidence=0.8):
|
||||
"""检查当前屏幕是否存在图片"""
|
||||
location = pyautogui.locateOnScreen(image_path, confidence=confidence)
|
||||
if location:
|
||||
print(f'图片: {image_path} 找到,坐标: {location}')
|
||||
return location
|
||||
else:
|
||||
print(f'没有找到图片: {image_path}')
|
||||
return None
|
||||
|
||||
def click_image_center(self, image_path, confidence=0.8):
|
||||
"""点击图片中心"""
|
||||
location = self.check_image_on_screen(image_path, confidence)
|
||||
if location:
|
||||
button_x, button_y = pyautogui.center(location)
|
||||
print(f'图片中心坐标: {button_x}, {button_y}')
|
||||
pyautogui.click(button_x, button_y)
|
||||
return True
|
||||
return False
|
||||
|
||||
def move_mouse_to(self, x, y):
|
||||
"""移动鼠标到指定坐标"""
|
||||
pyautogui.moveTo(x, y)
|
||||
print(f'鼠标移动到坐标: {x}, {y}')
|
||||
|
||||
def mouse_click(self):
|
||||
"""鼠标点击"""
|
||||
pyautogui.click()
|
||||
print('鼠标点击')
|
||||
|
||||
def scroll_mouse(self, delta):
|
||||
"""滚动鼠标滚轮"""
|
||||
pyautogui.scroll(delta)
|
||||
print(f'鼠标滚轮滚动: {delta}')
|
||||
|
||||
|
||||
def main():
|
||||
# 创建自动化点击器实例
|
||||
auto_clicker = AutoClicker()
|
||||
|
||||
# 加载PNG文件
|
||||
auto_clicker.load_png_list()
|
||||
|
||||
# 创建GUI
|
||||
root = tk.Tk()
|
||||
root.title("自动化点击器")
|
||||
root.geometry("480x320")
|
||||
|
||||
button_font = ("Arial", 12)
|
||||
# 修改背景色和文字颜色
|
||||
button_bg_color = "lightblue"
|
||||
button_fg_color = "black"
|
||||
button_border_width = 2
|
||||
|
||||
# 测试按钮
|
||||
def test_check_image():
|
||||
file = auto_clicker.png_files[0] if auto_clicker.png_files else "1.png"
|
||||
location = auto_clicker.check_image_on_screen(os.path.join(auto_clicker.src_folder, file))
|
||||
if location:
|
||||
messagebox.showinfo("测试结果", f"图片 {file} 找到!")
|
||||
else:
|
||||
messagebox.showerror("测试结果", f"图片 {file} 未找到!")
|
||||
|
||||
def test_click_image():
|
||||
file = auto_clicker.png_files[0] if auto_clicker.png_files else "1.png"
|
||||
if auto_clicker.click_image_center(os.path.join(auto_clicker.src_folder, file)):
|
||||
messagebox.showinfo("测试结果", f"点击图片 {file} 成功!")
|
||||
else:
|
||||
messagebox.showerror("测试结果", f"点击图片 {file} 失败!")
|
||||
|
||||
def test_move_mouse():
|
||||
auto_clicker.move_mouse_to(100, 100)
|
||||
messagebox.showinfo("测试结果", "鼠标已移动到 (100, 100)")
|
||||
|
||||
def test_mouse_click():
|
||||
auto_clicker.mouse_click()
|
||||
messagebox.showinfo("测试结果", "鼠标点击完成")
|
||||
|
||||
def test_scroll_mouse():
|
||||
auto_clicker.scroll_mouse(10)
|
||||
messagebox.showinfo("测试结果", "鼠标滚轮滚动完成")
|
||||
|
||||
def start_tasks():
|
||||
while True:
|
||||
# 在这里添加你的任务代码
|
||||
print("开始任务")
|
||||
time.sleep(1)
|
||||
print("任务结束")
|
||||
time.sleep(1)
|
||||
|
||||
# 创建按钮
|
||||
tk.Button(root, text="开始任务", command=start_tasks, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
tk.Button(root, text="测试检查图片", command=test_check_image, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
tk.Button(root, text="测试点击图片", command=test_click_image, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
tk.Button(root, text="测试移动鼠标", command=test_move_mouse, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
tk.Button(root, text="测试鼠标点击", command=test_mouse_click, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
tk.Button(root, text="测试滚动鼠标", command=test_scroll_mouse, font=button_font, bg=button_bg_color,
|
||||
fg=button_fg_color, bd=button_border_width).pack(pady=5)
|
||||
|
||||
# 启动GUI
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
@@ -0,0 +1,13 @@
|
||||
soup elephant glare success violin unusual blade swing twenty tent cable require trap major cloud item infant ensure proof glimpse bulk gain grape annual
|
||||
surge quit style joy armor save inside jungle man practice admit ball
|
||||
drama follow rhythm grit myth glow immense pretty sorry royal board armed virtual avocado meadow exist urge club major cool saddle dad regular cigar
|
||||
level blue fall burger famous thing subway zone undo panic clog voyage drum fade bracket bone attend pass level fetch trap brain client judge
|
||||
cry margin renew bean awful hedgehog canyon often ahead frame master crazy luggage gown desert entire enrich grape human item faculty satisfy occur kind
|
||||
cram kidney drip smart solar treat cry cushion volume under chief crowd today pond smart tomato net card shallow large act unlock boss private
|
||||
nerve expand focus fury topic benefit fruit coach win betray guard clarify sketch project cat prize define anxiety remember acoustic client cave noodle sword
|
||||
loud crucial output pony year attract lock barrel level entire price affair version shallow forward flock near badge mass box above future arm soup
|
||||
ethics hobby gun relax goose apple reduce frequent jungle affair rotate solid ready ridge siege tide when suggest cannon change display marble expand tired
|
||||
shaft dial garden surface dismiss kitchen clap ice manual answer spider walk open slogan earn cave boil magic wave olive medal sing dinner accident
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user