Simulate Mouse Clicks on Python

前端 未结 9 1939
渐次进展
渐次进展 2020-12-13 12:52

I\'m currently in the process of making my Nintendo Wiimote (Kinda sad actually) to work with my computer as a mouse. I\'ve managed to make the nunchuk\'s stick control actu

相关标签:
9条回答
  • 2020-12-13 13:42

    You can install the PyAutoGUI GUI automation module from PyPI (run pip install pyautogui) and then call the pyautogui.click() to click on a certain X and Y coordinates of the screen:

    >>> import pyautogui
    >>> pyautogui.click(50, 100)
    >>> pyautogui.moveTo(200, 200)
    

    PyAutoGUI works on Windows, Mac, and Linux, and on Python 2 and 3. It also can emulate the keyboard, do mouse drags, take screenshots, and do simple image recognition of the screenshots.

    Full docs are at https://pyautogui.readthedocs.org/

    0 讨论(0)
  • 2020-12-13 13:44

    I didn't see this mentioned, so here it goes - there is also python-dogtail; see:

    • Automated GUI testing with Dogtail | Red Hat
    • Testing/Automation/DogtailTutorial - Ubuntu Wiki

    It requires "Enable assistive technologies" in the Gnome Desktop - but can in principle obtain e.g. names of GUI buttons of an application, and allow virtual clicks on them (rather than via x/y coordinates).

    0 讨论(0)
  • 2020-12-13 13:45

    You can use PyMouse which has now merged with PyUserInput. I installed it via pip:

    1. apt-get install python-pip

    2. pip install pymouse

    In some cases it used the cursor and in others it simulated mouse events without the cursor.

    from pymouse import PyMouse
    
    m = PyMouse()
    m.position() #gets mouse current position coordinates
    m.move(x,y)
    m.click(x,y) #the third argument "1" represents the mouse button
    m.press(x,y) #mouse button press
    m.release(x,y) #mouse button release
    

    You can also specify which mouse button you want used. Ex left button:

    m.click(x,y,1)
    

    Keep in mind, on Linux it requires Xlib.

    0 讨论(0)
提交回复
热议问题