2

I searched in win32gui and PyAutoGUI some commands that make "long - click" on the left mouse button, and I didn't find anything. 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)
0

2 Answers 2

2

In theory, PyAutoGUI covers this with 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.
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.