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.
我正在尝试将从/ dev / input / event0读取的键盘事件从定义的值转换为未运行X或终端的嵌入式应用程序中的ASCII等效项。
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.
我认为这应该通过Linux中定义的键盘映射功能来完成,而不仅仅是创建我自己的std :: map <>但我似乎无法找到一个好的起点。到目前为止,我发现的大多数示例都假设我使用的是X窗口或终端。
2 个解决方案
#1
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.
文本输入(传统美国键盘和7位ASCII标准的非常简单的情况除外)是一个非常复杂的领域。我非常强烈建议您使用X客户端执行此操作,您可以在其中利用所有现有的输入方法。
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.
但是如果你必须,并且你对一种键盘和一种语言感到满意,那么你可以通过解释事件就像终端一样。检查/usr/include/linux/input.h中的定义值。跟踪Shift和Ctrl键的位置(非ASCII键,如Alt,Fn等......当然由你来解释)并在键上事件中发出相应的字节。如果默认值对您的应用程序不起作用,也许您也想要实现自动重复功能。
But basically: don't. This is a much (!) harder problem than you seem to realize.
但基本上:不。这是一个比你似乎意识到的更难(!)更难的问题。
#2
0
You can read the below structure from /dev/input/event0
您可以从/ 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
有关更多详细信息,请访问:https://www.kernel.org/doc/Documentation/input/input.txt
#1
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.
文本输入(传统美国键盘和7位ASCII标准的非常简单的情况除外)是一个非常复杂的领域。我非常强烈建议您使用X客户端执行此操作,您可以在其中利用所有现有的输入方法。
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.
但是如果你必须,并且你对一种键盘和一种语言感到满意,那么你可以通过解释事件就像终端一样。检查/usr/include/linux/input.h中的定义值。跟踪Shift和Ctrl键的位置(非ASCII键,如Alt,Fn等......当然由你来解释)并在键上事件中发出相应的字节。如果默认值对您的应用程序不起作用,也许您也想要实现自动重复功能。
But basically: don't. This is a much (!) harder problem than you seem to realize.
但基本上:不。这是一个比你似乎意识到的更难(!)更难的问题。
#2
0
You can read the below structure from /dev/input/event0
您可以从/ 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
有关更多详细信息,请访问:https://www.kernel.org/doc/Documentation/input/input.txt