-
Notifications
You must be signed in to change notification settings - Fork 39
Linux Xtest via Xlib
pepijndevos edited this page Sep 13, 2010
·
2 revisions
This is the preferred way to control the mouse on Linux. Python-Xlib is in most package managers or included by default, and has proven to be more reliable that straight Xlib.
This method is much like the XTest from pypi But needs a few extra steps.
As with Xlib, we need several packages:
from Xlib.display import Display
from Xlib import X
from Xlib.ext.xtest import fake_input
Like with Xlib, we need a display, but no root and other calculations this time:
display = Display()
The button events. We need both press and release.
fake_input(display, X.ButtonPress, button)
fake_input(display, X.ButtonRelease, button)
The motion event is a little different, keyword arguments are used to avoid all the other parameters that come before x and y:
fake_input(display, X.MotionNotify, x=x, y=y)
This is Xlib after all, so we weed to sync before anything is going to happen:
display.sync()