Simulate Mouse Clicks on Python Simulate Mouse Clicks on Python python python

Simulate Mouse Clicks on Python


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 PyMousem = PyMouse()m.position() #gets mouse current position coordinatesm.move(x,y)m.click(x,y) #the third argument "1" represents the mouse buttonm.press(x,y) #mouse button pressm.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.


The evdev package provides bindings to parts of the input handling subsystem in Linux. It also happens to include a pythonic interface to uinput.

Example of sending a relative motion event and a left mouse click with evdev:

from evdev import UInput, ecodes as ecapabilities = {    e.EV_REL : (e.REL_X, e.REL_Y),     e.EV_KEY : (e.BTN_LEFT, e.BTN_RIGHT),}with UInput(capabilities) as ui:    ui.write(e.EV_REL, e.REL_X, 10)    ui.write(e.EV_REL, e.REL_Y, 10)    ui.write(e.EV_KEY, e.BTN_LEFT, 1)    ui.syn()