V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ljspkclks
V2EX  ›  Python

PyHook3 鼠标监听 并 鼠标点击延迟 0.3~1.1 秒问题

  •  1
     
  •   ljspkclks · 2019-10-12 19:09:00 +08:00 · 2622 次点击
    这是一个创建于 1658 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请诸位看代码。 不知道为什么用 Pyhook3 监听鼠标事件后执行鼠标点击命令的话会出现延迟 1 秒左右并且之后的点击命令不会延迟的问题。

    import pythoncom
    import PyHook3 as pyHook
    import win32api
    import time
    from pymouse import *
    
    
    def main(function):
        # 创建狗子
        hm = pyHook.HookManager()
        # 监听鼠标上台
        hm.MouseLeftUp = lambda x: function(hm, x, pythoncom)
        # 开始监听
        hm.HookMouse()
        # 进入循环
        pythoncom.PumpMessages(10000)
    def start(hm, event, pythoncom):
        people_1 = list(event.Position)
        if people_1[0] > 50 or people_1[1] > 50:
            return True
        hm.UnhookMouse()
        win32api.PostQuitMessage()
        click_left_test(600,600)
        click_left_test(600,600)
        hm.HookMouse()
        pythoncom.PumpMessages(10000)
        return True
    
    def click_left_test(x, y):
        x1 = time.time()
        print('之前的时间:', x1)
        m.click(x, y, button=1)
        y1 = time.time()
        print('之后的时间:', y1)
        print("之间差", y1 - x1)
    m = PyMouse()
    main(start)
    
    2 条回复    2019-10-13 15:58:58 +08:00
    ljspkclks
        1
    ljspkclks  
    OP
       2019-10-12 19:09:42 +08:00
    之前的时间: 1570878442.8022747
    之后的时间: 1570878443.8039594
    之间差 1.0016846656799316
    之前的时间: 1570878443.8039594
    之后的时间: 1570878443.809815
    之间差 0.005855560302734375


    这些是结果
    ljspkclks
        2
    ljspkclks  
    OP
       2019-10-13 15:58:58 +08:00
    没人可以回答这个难题吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2894 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:47 · PVG 15:47 · LAX 00:47 · JFK 03:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.