7

I'm trying to convert keyboard events read from /dev/input/event0 from the values defined in to their ASCII equivalent inside an embedded application that is not running X or a terminal.

I think this should be done via keymap functionality defined within Linux rather than just creating my own std::map<> but I can't seem to find a good place to start. Most of the examples I have found so far assume I am running with X windows or with a terminal.

4
  • Finding the source code of whatever implements the terminal could be interesting. Though it may be buried under 40+ years of abstraction to support legacy terminals. Commented Jul 11, 2012 at 15:33
  • Yes, been digging through kdb-1.12.tar.gz but kept losing the trail. Commented Jul 11, 2012 at 17:14
  • Does this help? Posted by Derek@TheDailyLinux in Programming » Grab Raw Keyboard Input from Event Device Node (/dev/input/event) Commented Aug 28, 2012 at 16:16
  • Did you ever figure it out? I have the exact same problem and cannot find a solution Commented Nov 20, 2019 at 23:47

2 Answers 2

1

Text input (except for the very simple case of the traditional US keyboard and the 7 bit ASCII standard) is an immensely complicated field. I'd very strongly suggest you do this using an X client, where you can take advantage of all the existing input methods.

But if you must, and you're happy with one kind of keyboard and one language, you do this by interpreting the events just as a terminal would. Check the defintion in /usr/include/linux/input.h for the values. Track the position of the Shift and Ctrl keys (non-ASCII keys like Alt, Fn, etc... are up to you to interpret, of course) and emit the corresponding byte on the key up event. Maybe you'll want to implement an auto-repeat facility too if the defaults don't work for you application.

But basically: don't. This is a much (!) harder problem than you seem to realize.

Sign up to request clarification or add additional context in comments.

Comments

0

You can read the below structure from /dev/input/event0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.