将ASCII字符转换为x11键码

编程入门 行业动态 更新时间:2024-10-09 04:21:50
本文介绍了将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?

推荐答案

您可以使用 XStringToKeysym ,以将至少字母数字字符转换为KeySym s,后跟 XKeysymToKeycode 转换为KeyCode s:

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字符(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键码

本文发布于:2023-11-26 05:15:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符   ASCII   键码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!