问题描述
我有一个小程序,可以输入ascii字符的形式.我需要能够将这些转换为与x11函数一起使用的键码.是否有xlib函数来执行此操作或另一个库?还是大型的开关盒效果最好?
I have a small program that takes input in the form of ascii characters. I need to be able to convert these to keycodes for use with x11 functions. Is there a xlib function to do this or another library? Or will a large switch case work best?
推荐答案
您可以使用 XStringToKeysym
,以将至少字母数字字符转换为KeySym
s,后跟 XKeysymToKeycode
转换为KeyCode
s:
You can use XStringToKeysym
to convert at least alphanumeric characters to KeySym
s, followed by XKeysymToKeycode
for conversion to KeyCode
s:
Display *display = ...;
KeySym sym_a = XStringToKeysym("A");
KeyCode code_a = XKeysymToKeycode(display, sym_a);
正如@BobDoolitle在他的答案中指出的那样,虽然XStringToKeysym
适用于字母数字单字符字符串,但它失败在ASCII的一般情况下.他提供了一种处理大多数ASCII字符(0x20
– 0x7F
)的方法,尽管超出该范围的字符需要更仔细的处理.
As @BobDoolitle pointed out in his answer, while XStringToKeysym
works for alphanumeric single-character strings, it fails in the ASCII general case. He provides a way to trivially handle the majority of ASCII characters (0x20
–0x7F
) although characters outside that range require more careful treatment.
这篇关于将ASCII字符转换为x11键码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!