1
votes

I was wondering if anyone knew how to convert a key represented in ascii to linux input_event keycodes.

When I say ascii please refer to this graph: https://en.wikipedia.org/wiki/File:ASCII-Table.svg

When I say linux input_event keycodes please refer to this graph: https://elixir.bootlin.com/linux/v4.6/source/include/uapi/linux/input-event-codes.h

I understand I could just use a map between these but I was wondering if there was a more official way to do it. And yes I have taken a look at this solution: Convert ASCII character to x11 keycode but I'd like to not be dependent on X11 if possible for the solution.

Edit:

This question is not a duplicate of How can I translate Linux keycodes from /dev/input/event* to ASCII in Perl?. Explained in my answer below.

1
I would say a simple lookup table would work just fine. But you can try to read Gdk's documentation. Maybe they have a function that does that, however making a library like Gdk a dependency just for this seems like an overkill solution. - Iharob Al Asimi
It seems here there's an answer with a C solution: stackoverflow.com/questions/2547616/… - Sir Jo Black
Not a duplicate, but it is close. I addressed this in my answer - ktb92677

1 Answers

0
votes

It has been suggested on multiple occasions that this might be a duplicate of this question: How can I translate Linux keycodes from /dev/input/event* to ASCII in Perl?. This answers the question of converting from input_event keycodes to ascii, not from ascii to keycode. That being said It looks like that code can be reverse engineered to work for my case as well.