使用pyautogui时应用程序如何获得鼠标移动 [英] How application get mouse movement when using pyautogui

查看:49
本文介绍了使用pyautogui时应用程序如何获得鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在没有pyautogui的情况下通过应用程序移动鼠标时,例如windows计算器,计算器的按钮会改变它的颜色.看来,计算器捕捉到了我鼠标的移动.
像这样,您可以看到按钮 9 的颜色变为灰色:


但是当我使用 pyautogui 时,调用 pyautogui.moveTo 函数.我可以看到鼠标光标移动到正确的位置,但按钮 9 的颜色保持白色.

我确定传递给函数 pyautogui.moveTo 的 x,y 位置是正确的.如果我调用 pyautogui.click(),计算器上会显示数字 9.

有什么方法可以确保应用程序识别由 pyautogui 触发的运动?

谢谢

解决方案

好吧,虽然我真的没有看到这里有什么问题,如果它让您感到如此麻烦,请尝试使用 moveTo() 函数的第三个参数.

<预><代码>>>>pyautogui.moveTo(100, 200, 2) # 在 2 秒内将鼠标移动到 100 的 X,200 的 Y

在这里它会在两秒内缓慢滑过并产生悬停效果.如果持续时间小于 pyautogui.MINIMUM_DURATION 移动将是即时的.默认情况下,pyautogui.MINIMUM_DURATION 为 0.1.

希望这会有所帮助.

When I move mouse without pyautogui pass by a application, for example windows calculator, button of calculator will change it's color. It seems that, calculator captured the movement of my mouse.
Like this, you can see button 9 color changed to gray:


But when I use pyautogui, invoke pyautogui.moveTo function. I can see the mouse cursor move to the correct location, but button 9's color keep white.

I'm sure that the x,y possion pass to function pyautogui.moveTo is correct. If I invoke pyautogui.click(), number 9 is showed on calculator.

Is there any way to ensure that application recognize the movement triggered by pyautogui?

Thank you

解决方案

Well Although I don't really see a problem here if it bugs you that much try to use the third argument for the moveTo() function.

>>> pyautogui.moveTo(100, 200, 2)   # moves mouse to X of 100, Y of 200 over 2 seconds

Here it will slide over slowly in two seconds and will give the hover effect. If the duration is less than pyautogui.MINIMUM_DURATION the movement will be instant. By default, pyautogui.MINIMUM_DURATION is 0.1.

Hope this helps.

这篇关于使用pyautogui时应用程序如何获得鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆