鼠标手辅助器

发布于:2024-04-28 ⋅ 阅读:(25) ⋅ 点赞:(0)

鼠标发生移动后 ,静止在某位置指定时间后即可触发点击事件
支持多种点击事件,支持快捷键触发,支持自定义配置

有其他更好的思路 ,支持有偿定制,留言留下联系方式,看到会加你

# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: test.py
@time: 2024/4/11 0:04
@desc:

"""
import pyautogui
import keyboard
import time
from threading import Thread
import atexit


class MouseClick(object):
    """

    """

    def __init__(self,time_click_interval):
        atexit.register(self.exit_handler)
        # 位置收集开关
        self.flag_open_close = True
        # 点击间隔
        self.time_click_interval = time_click_interval
        # 点击模式
        self.click_mode = 1
        # 此处静止 点击过
        self.forbidden = False

        self.thread = Thread(target=self.monitor_keyboard)
        self.thread.start()

    def exit_handler(self):
        """
        程序退出自动执行
        :return:
        """
        input("\n\n\n程序终止,回车退出")

    def monitor_keyboard(self):
        """

        :return:
        """
        keyboard.on_press(self.on_combination_pressed_click)
        keyboard.on_press(self.on_combination_pressed_doubleClick)
        keyboard.on_press(self.on_combination_pressed_tripleClick)
        keyboard.on_press(self.on_combination_pressed_down)
        keyboard.on_press(self.on_combination_pressed_pause)
        keyboard.on_press(self.on_combination_pressed_click_right)
        keyboard.wait('esc')

    def monitor_mouse_move(self, x, y):
        """

        :param x:
        :param y:
        :return:
        """
        if self.flag_open_close:
            if self.click_mode == 1:
                pyautogui.click(x, y)
                print(f"单击:x:{x}, y:{y}")
            elif self.click_mode == 2:
                pyautogui.doubleClick(x, y)
                print(f"双击:x:{x}, y:{y}")
            elif self.click_mode == 3:
                pyautogui.tripleClick(x, y)
                print(f"三击:x:{x}, y:{y}")
            elif self.click_mode == 4:
                pyautogui.rightClick(x, y)
                print(f"右键单击:x:{x}, y:{y}")

    def on_combination_pressed_pause(self,event):
        """
        单击
        :param event:
        :return:
        """
        if keyboard.is_pressed('ctrl') and keyboard.is_pressed('`'):
            if self.flag_open_close:
                self.flag_open_close = False
                print("【暂停】:ctrl+`")
            else:
                self.flag_open_close = True
                print("【开启】:ctrl+`")



    def on_combination_pressed_click(self,event):
        """
        单击
        :param event:
        :return:
        """
        if keyboard.is_pressed('ctrl') and keyboard.is_pressed('shift') and keyboard.is_pressed('1'):
            self.click_mode = 1
            print("【单击模式】:ctrl+shift+1")

    def on_combination_pressed_click_right(self,event):
        """
        单击
        :param event:
        :return:
        """
        if keyboard.is_pressed('tab'):
            self.click_mode = 4
            print("【右键单击模式】:tab")

    def on_combination_pressed_doubleClick(self,event):
        """
        双击
        :param event:
        :return:
        """
        if keyboard.is_pressed('ctrl') and keyboard.is_pressed('shift') and keyboard.is_pressed('2'):
            self.click_mode = 2
            print("【双击模式】:ctrl+shift+2")

    def on_combination_pressed_tripleClick(self,event):
        """
        三击
        :param event:
        :return:
        """
        if keyboard.is_pressed('ctrl') and keyboard.is_pressed('shift') and keyboard.is_pressed('3'):
            self.click_mode = 3
            print("【三击模式】:ctrl+shift+3")


    def on_combination_pressed_down(self,event):
        """
        长按 可拖动窗体
        :param event:
        :return:
        """
        if keyboard.is_pressed('alt'):
            pyautogui.mouseDown()
            print("【左键长按模式】:alt")


    def process(self):
        """

        :return:
        """
        print("鼠标手辅助器 启动")
        print("点击间隔:",self.time_click_interval )
        prev_x, prev_y = pyautogui.position()
        while True:
            try:
                current_x, current_y = pyautogui.position()
                if current_x != prev_x or current_y != prev_y:
                    prev_x, prev_y = current_x, current_y
                else:
                    start_time = time.time()
                    while True:
                        new_x, new_y = pyautogui.position()
                        if new_x != current_x or new_y != current_y:
                            self.forbidden = False
                            break
                        if time.time() - start_time >= self.time_click_interval:
                            if not self.forbidden:
                                self.monitor_mouse_move(new_x, new_y)
                                self.forbidden = True
                            break

                if keyboard.is_pressed("esc"):
                    print("【退出】ESC")
                    break
            except Exception as e:
                print("【错误】:请勿将鼠标移动到边缘区域")




if __name__ == '__main__':
    time_click_interval = input("请输入点击间隔时间(单位:秒):")
    # time_click_interval = 3
    mc = MouseClick(float(time_click_interval))
    mc.process()


网站公告

今日签到

点亮在社区的每一天
去签到