I'm facing this issue with my mouse. In my particular case the duplicate click events are less than 100ms after the genuine event. Is it possible for me to write an event filter for my display server so that all mouse events pass through a program written by me, with the ability to drop certain events? I'm using X display server with awesome wm.
1 Answer
I'd do this on the kernel input layer. The uinput
device allows you to write a userspace program that produces input layer events. If you open your mouse input device (look at /dev/input/by-id
and /dev/input/by-path
to identify it correctly between boots) with the grab
option, then the original events will go exclusively to your program, and not to X. The X evdev driver will pick up your new device automatically.
Here is an example C program, there is also a Python library (Pypi) if you prefer Python, and probably libraries for other programming languages as well. Documentation and more sample programs are easy to google.
Usage examples copied from python-uinput:
Generate keyboard clicks
import uinput
with uinput.Device([uinput.KEY_E, uinput.KEY_H,
uinput.KEY_L, uinput.KEY_O]) as device:
device.emit_click(uinput.KEY_H)
device.emit_click(uinput.KEY_E)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_O)
Move mouse cursor
import uinput
with uinput.Device([uinput.REL_X, uinput.REL_Y,
uinput.BTN_LEFT, uinput.BTN_RIGHT]) as device:
for i in range(20):
device.emit(uinput.REL_X, 5)
device.emit(uinput.REL_Y, 5)
Generate keyboard combinations
import uinput
with uinput.Device([uinput.KEY_LEFTALT, uinput.KEY_TAB]) as device:
device.emit_combo([uinput.KEY_LEFTALT, uinput.KEY_TAB])
-
Project links of the Python library are dead. Could you write a more complete example in your answer?– jarnoCommented Aug 14, 2021 at 4:29
-
I could not find documentation for python-uinput, but I could find some for python-evdev but I am not sure if it is for same purpose. How do you open a device with
grab
option?– jarnoCommented Aug 15, 2021 at 15:41 -
@jarno python-evdev now also includes a class for
UInput
. In general, "evdev" is about events generated from the kernel input layer, "uinput" is about making your own virtual device in that layer.evdev.device.InputDevice
in python-evdev has agrab
option, RTFM.– dirktCommented Aug 15, 2021 at 16:41 -
I was actually reading it but I am not yet familiar with the module besides I am novice in Python.– jarnoCommented Aug 15, 2021 at 16:43