简体   繁体   English

如何在 Python 中模拟右键单击?

[英]How do you simulate a right-click in Python?

I cannot find this information anywhere, including its documentation - is this non existent?我在任何地方都找不到这些信息,包括它的文档——这不存在吗?

doesn't matter anymore, I have found a workaround that works for now.不再重要了,我找到了一种现在可行的解决方法。

Here's my attempt at a solution.这是我对解决方案的尝试。

According to project description of PyDirectInput , this library is suppose to replicate the functionality of PyAutoGUI mouse and keyboard inputs.根据PyDirectInput的项目描述,这个库是假设复制 PyAutoGUI 鼠标和键盘输入的功能。

In addition, this library works in conjunction with PyAutoGUI .此外,此库与PyAutoGUI结合使用。

This would lead me to believe that using the click() documentation of PyAutoGUI and replacing it with pydirectinput would result in the following solution:这会让我相信使用 PyAutoGUI 的click() 文档并将其替换为 pydirectinput 会导致以下解决方案:

import pyautogui
import pydirectinput

pydirectinput.click(button='right')

However not all optional parameters and features may be available for a particular function.然而,并非所有可选参数和功能都可用于特定 function。

On the bright side, click() is listed among the features implemented.从好的方面来说,click() 被列在实现的功能中。

There may be a chance that this parameter may not be implemented.该参数可能无法实现。 If it's not implemented, the author Ben Johnson is open to new feature implementation.如果没有实现,作者 Ben Johnson 对新功能实现持开放态度。 Perhaps you can work with the author to implement this parameter.或许你可以和作者一起实现这个参数。

I would give this code a try.我会试试这个代码。

If the code above worked and other tasks must be accomplished in PyDirectInput, I would look at the list of features implemented (towards bottom of the page) with the documentation of PyAutoGUI .如果上面的代码有效并且必须在 PyDirectInput 中完成其他任务,我将使用PyAutoGUI 的文档查看实现的功能列表(靠近页面底部)。 Then I would apply the same methodology used for the provided code solution to code the other tasks.然后,我将应用与提供的代码解决方案相同的方法来编写其他任务。

I hope this helped.我希望这会有所帮助。

You can just do:你可以这样做:

import pydirectinput
pydirectinput.rightClick()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM