简体   繁体   English

触发鼠标左键“长按”的命令

[英]Command to trigger “long click” on left mouse button

I searched in win32gui and PyAutoGUI some commands that make "long - click" on the left mouse button, and I didn't find anything.我在 win32gui 和 PyAutoGUI 中搜索了一些使鼠标左键“长按”的命令,但没有找到任何东西。 I'm actually building a code that helps me to remote another pc's mouse so i need a command that makes a long click on a mouse.我实际上正在构建一个代码来帮助我远程控制另一台电脑的鼠标,所以我需要一个可以长按鼠标的命令。

I put *** on my code so you can see the parts where I need help:我把***放在我的代码上,这样你就可以看到我需要帮助的部分:

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)

In theory, PyAutoGUI covers this with mouseDown & mouseUp functions .理论上,PyAutoGUI 使用mouseDown 和 mouseUp 函数覆盖了这一点。

>>> 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.

A solution might be:一个解决方案可能是:

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

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

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