我在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/