用鼠标左键触发“长按”的命令
问题描述:
我在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.