How can I translate Linux key codes from / dev / input / event * to ASCII

I am trying to convert keyboard events from / dev / input / event 0 from the values ​​defined in their ASCII equivalent to an embedded application that does not work X or terminal.

I think this should be done using the keyboard functions defined in Linux, and not just to create my own std :: map <> but I cannot find a suitable place to start. Most of the examples that I have found so far suggest that I work with X windows or with a terminal.

+6
source share
2 answers

Typing (except in the very simple case of the traditional American keyboard and the 7-bit ASCII standard) is an extremely complex field. I highly recommend you do this with the X client, where you can use all existing input methods.

But if you need, and you are satisfied with one keyboard and one language, you do this by interpreting events in the same way as a terminal. Check the values ​​in /usr/include/linux/input.h for the values. Tracking the position of the Shift and Ctrl keys (non-ASCII keys such as Alt, Fn, etc.) suits you to interpret, of course) and emit the corresponding byte in the key up event. You might also want to implement an auto-repeat facility if the defaults do not work for your application.

But in principle: no. This is a difficult problem (!) Than you seem to understand.

+1
source

You can read the structure below from / dev / input / event 0

 struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; }; 

More details: https://www.kernel.org/doc/Documentation/input/input.txt

0
source

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


All Articles