python - 如何在不触发系统功能的情况下捕捉鼠标点击

问题描述

我是新来的程序,我需要这样的功能: 返回鼠标指针的位置,然后单击右键。

我写了一些类似下面的代码,但是右键单击会触发一些功能,例如在位置返回时打开菜单

如何防止这种情况发生?

谢谢。

PS:我找到了一些“pyHook”的方法,但是中文版系统有问题。我解决不了。

import pyautogui
import win32api
import win32con
from threading import Timer
from pywinauto.win32_hooks import Hook
from pywinauto.win32_hooks import MouseEvent


def on_timer():
    win32api.PostThreadMessage(main_thread_id,win32con.WM_QUIT,0);


def on_event(args):
    if isinstance(args,MouseEvent):
        if args.current_key == 'RButton' and args.event_type == 'key down':
            x,y = pyautogui.position()
            print("Right button pressed at %s,%s" % (x,y))
            return False


hk = Hook()
hk.handler = on_event
main_thread_id = win32api.GetCurrentThreadId()
t = Timer(5.0,on_timer)
t.start()
hk.hook(keyboard=False,mouse=True)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)