Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about emulating touch events #158

Open
makeevolution opened this issue Jun 3, 2021 · 1 comment
Open

Question about emulating touch events #158

makeevolution opened this issue Jun 3, 2021 · 1 comment

Comments

@makeevolution
Copy link

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?

@LinusCDE
Copy link
Contributor

LinusCDE commented Jun 3, 2021

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 some BTN_* 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants