python - 鼠标左键触发 "long click"的命令

标签 python winapi mouse remote-access pyautogui

我在win32gui和PyAutoGUI中搜索了一些使鼠标左键“长按”的命令,但没有找到任何东西。 我实际上正在构建一个代码来帮助我远程控制另一台电脑的鼠标 所以我需要一个可以长按鼠标的命令。

我在代码中添加了***,以便您可以看到我需要帮助的部分:

import win32api
import time


state_left = win32api.GetKeyState(0x01)  # Left button down = 0 or 1. Button up = -127 or -128
while True:
    a = win32api.GetKeyState(0x01)
    if a != state_left:  # Button state changed
        state_left = a
        print(a)
        if a < 0:
            # *** long click on left mouse button ***
            print('Left Button Pressed')
        else:
            # *** stop click on left mouse button ***
            print('Left Button Released')
    time.sleep(0.001)

最佳答案

理论上,PyAutoGUI 用 mouseDown & mouseUp functions 涵盖了这一点。 .

>>> pyautogui.mouseDown(); pyautogui.mouseUp()  # does the same thing as a left-button mouse click
>>> pyautogui.mouseDown()  # press the left button down
>>> pyautogui.mouseUp(x=100, y=200)  # move the mouse to 100, 200, then release the button up.

关于python - 鼠标左键触发 "long click"的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44294666/

相关文章:

winapi - Windows : Mouse Down on Window Decoration

python - 在python中解压没有临时文件的bz2 url

python - matplotlib中直方图的X轴乱序

python - 从 Selenium 中的 Twitter 视频页面查找直接视频链接属性

影响窗口标题的 C++ 指针问题

c# - 更改鼠标按钮功能

textbox - 在 IE9 中,在禁用的文本框中突出显示文本不会释放鼠标按钮;解决方法?

python - 学习开发、部署和/或托管 Django 的最佳书籍和资源是什么?

c - 在C中隐藏应用程序窗口

c++ - 相对路径问题 - 一个 dir up