How to execute a keyboard event on Linux using the input subsystem

I am writing a Linux program in C and I need to grab some keyboard strokes.

Using the input subtype (read / write / dev / input / eventX), I can get the keyboard move (using the "read" function) or simulate the keyboard move (using the "write" function).

When using the β€œread” function, I can capture the strokes of the user's keyboard, but this event is propagating, and I do not know how to use it.

+6
source share
1 answer

By default, input events are sent to all listening applications and drivers. However, it is possible that the application will capture the device through the evdev interface - look at EVIOCGRAB ioctl() . This will allow only a specific application to receive events from that particular device.

The problem with this approach is that you cannot prevent the propagation of a specific event after it is received - you can only capture the device in advance, and then capture all the events. Therefore, if you want to filter input events, you must use a workaround.

The workaround I used in my evmapd included capturing the source device and using the uinput subsystem to provide another device with all the changes I needed, including reassigned keys and various other changes ...

+5
source

Source: https://habr.com/ru/post/924354/


All Articles