Question about emulating touch events
I saw in the injecting input section of the documentation that the library "accepts only KEY_* events by default". Does this mean I cannot inject touch events (like touching, swiping, etc.), and if I am wrong, how would I go about injecting such an touch event?
With "by default", I think they mean that when creating a device, they say to support Keyboard events since it's the most common use case. Evdev devices usually specify all the keys they'll ever send beforehand to allow other programs to classify them by. You can simply specify your own events=.
Here is an example I did that basically proxied Wacom touch events from an embedded device to a host computer: https://github.com/LinusCDE/rmTabletDriver/blob/738294772d613ab42478db98ded2faf3d68f8c47/tabletDriver.py#L43
I don't think that such a thing as a "swipe" event exists within evdev. You probably need to fake the swipe by sending the fitting touch events. You should also consider what type of "touch events" you want to send.
- Touchpads usually are relative event (
REL_*) - Multitouch (with one or more fingers) usually starts with
ABS_MT_. You should also specify the AbsInfo since the touch screen size rarely matches the screen resolution (my example above does it as well). Not all multitouch screns have the same event behaviour. - Drawing tablets / pen input (like a Wacom tablet or anything with an EMR pen). Those usually start with
ABS_. They also use someBTN_*events to denote when the pen gets in reach or the "rubber side/tool" is used.
The best thing is probably to look at the emitted events of the device type you want to fake (using evtest). Mutitouch (MT) for example usually increases the ABS_MT_TRACKING_ID and keeps track of fingers by changing the ABS_MT_SLOT before each X, Y coordinate events.
Here are some example codes uses for the reMarkable tablet (an embedded eink device aimed at notetaking). The marked lines are a typical Multitouch screen (like on smartphones). The codes and names should match with the ecodes of python-evdev. https://github.com/canselcik/libremarkable/blob/master/src/input/ecodes.rs#L13-L21