1

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.

ktb92677
  • 407
  • 4
  • 16
  • 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 Jun 29 '19 at 16:12
  • It seems here there's an answer with a C solution: https://stackoverflow.com/questions/2547616/how-can-i-translate-linux-keycodes-from-dev-input-event-to-ascii-in-perl/8438333 – Sir Jo Black Jun 29 '19 at 17:04
  • 1
    Possible duplicate of [How can I translate Linux keycodes from /dev/input/event\* to ASCII in Perl?](https://stackoverflow.com/questions/2547616/how-can-i-translate-linux-keycodes-from-dev-input-event-to-ascii-in-perl) – kiner_shah Jun 29 '19 at 17:40
  • Not a duplicate, but it is close. I addressed this in my answer – ktb92677 Jun 29 '19 at 17:48

1 Answers1

0

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.

ktb92677
  • 407
  • 4
  • 16