将ASCII字符转换为x11键码 [英] Convert ASCII character to x11 keycode

查看:207
本文介绍了将ASCII字符转换为x11键码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小程序,可以输入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?

推荐答案

您可以使用

You can use XStringToKeysym to convert at least alphanumeric characters to KeySyms, followed by XKeysymToKeycode for conversion to KeyCodes:

Display *display = ...;
KeySym sym_a = XStringToKeysym("A");
KeyCode code_a = XKeysymToKeycode(display, sym_a);


正如@BobDoolitle在他的答案中指出的那样,虽然XStringToKeysym适用于字母数字单字符字符串,但它失败在ASCII的一般情况下.他提供了一种处理大多数ASCII字符(0x200x7F)的方法,尽管超出该范围的字符需要更仔细的处理.


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 (0x200x7F) although characters outside that range require more careful treatment.

这篇关于将ASCII字符转换为x11键码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆