How to emulate a mouse click + drag?

Created by a
Keywords:
Last updated by:
a

Emulating a mouse click + drag is quite straightforward. Clicking and dragging consists of three different events:
1. press mouse
2. move mouse
3. release mouse

The following code snippet generates exactly those input events:

import uinput

events = (
    uinput.REL_X,
    uinput.REL_Y,
    uinput.BTN_LEFT,
    uinput.BTN_RIGHT,
    )

device = uinput.Device(events)

device.emit(uinput.BTN_LEFT, 1)
device.emit(uinput.REL_X, 100)
device.emit(uinput.BTN_LEFT, 0)