鼠标连点器——脚本版

# This is a sample Python script.
from pynput import mouse
from pynput import keyboard
import threading
import time
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


class MouseClick:
keyboard = ""
start_multi_click = False
# 鼠标对象
mouse = mouse.Controller()
# 键盘监控
keyboard_listener = None
mouse_listener = None
# 运行
running = True
# 鼠标信息
x, y, button = 0, 0, None

def __init__(self):
self.keyboard_listener = keyboard.Listener(on_release=self.on_release, on_press=self.on_press)
self.keyboard_listener.start()

self.mouse_listener = mouse.Listener(on_click=self.on_click)
self.mouse_listener.start()

def on_press(self, key):
"""释放按键"""
self.keyboard = key.name if hasattr(key, "name") else str(key)

def on_release(self, key):
"""释放按键"""
self.keyboard = ""

if hasattr(key, "name") and key.name == "esc":
self.running = False

def on_click(self, x, y, button, pressed):
"""获取鼠标信息"""
if pressed:
self.x = x
self.y = y
self.button = button
print(self.x, self.y, self.button)

def run(self):
"""循环监控鼠标和键盘"""
while True:
# 退出连点器
if not self.running:
break

# shift + button 执行连点, 执行连点后恢复鼠标信息
if self.keyboard == "shift" and self.x and self.y and self.button:
print(self.x, self.y, self.button)
# 连点9次加上触发的1次总共为10次
self.mouse.click(self.button, 9)
self.x = 0
self.y = 0
self.button = None

# 监控频率
time.sleep(0.1)

# 释放资源
self.keyboard_listener.stop()
self.mouse_listener.stop()


def new_thread_start():
mouse = MouseClick()
mouse.run()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
mouse1 = mouse.Controller()
mouse1.click(mouse.Button.left, 9)
mouse_t = threading.Thread(target=new_thread_start, args=())
mouse_t.start()
posted @ 2023-12-21 00:53  你看起来真的很好吃  阅读(734)  评论(0编辑  收藏  举报