命令触发"长按"在鼠标左键上

时间:2017-05-31 21:05:27

标签: python winapi mouse remote-access pyautogui

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

我将***放在我的代码上,以便您可以看到我需要帮助的部分:

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)

2 个答案:

答案 0 :(得分:1)

解决方案可能是:

pyautogui.dragTo(100, 200, button='left')     # drag mouse to X of 100, Y of 200 while holding down left mouse button
pyautogui.dragTo(300, 400, 2, button='left')  # drag mouse to X of 300, Y of 400 over 2 seconds while holding down left mouse button
pyautogui.drag(30, 0, 2, button='right')   # drag the mouse left 30 pixels over 2 seconds while holding down the right mouse button

答案 1 :(得分:-1)

理论上,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.