[英]X11/Xlib c/c++ char to XKeyEvent keycode
My need is to convert a char into a keycode to send an event with XSendEvent
. 我需要将char转换为键码,以使用XSendEvent
发送事件。
I'm using XStringToKeysym("a")
, but when I use chars like :
I get an invalid result. 我正在使用XStringToKeysym("a")
,但是当我使用如下字符时:
我得到了无效的结果。
Is it possible to bypass use of keysym and convert char directly to XKeyEvent
keycode? 是否可以绕过使用keysym并将char直接转换为XKeyEvent
键码?
Any help appreciated! 任何帮助表示赞赏!
You can get the Unicode representation of the character and prepend U
to it. 您可以获取字符的Unicode表示形式,并在字符前加上U
For instance, in case of :
these would do the same thing: 例如,在以下情况下:
这些会做同样的事情:
XStringToKeysym("colon")
XStringToKeysym("U003A")
Actually, you can do better than @Artyom's answer. 实际上,您可以比@Artyom的答案做得更好。 If you look at <X11/keysymdef.h>
you find that for ASCII
0x20-0xFF, the characters map directly to XKeySyms
. 如果查看<X11/keysymdef.h>
则会发现对于ASCII
0x20-0xFF,字符直接映射到XKeySyms
。 So, I'd say it's simpler to just use that range of characters directly as KeyCodes
, and just map the remaining 32 characters. 因此,我想说直接将该范围的字符用作KeyCodes
并映射其余的32个字符会更简单。
For a more detailed answer including example code, see: https://stackoverflow.com/a/25771958/3149905 有关包括示例代码的更详细的答案,请参阅: https : //stackoverflow.com/a/25771958/3149905
XStringToKeysym
converts a name to a keysym, so ":"
won't work, you have to use "colon"
instead. XStringToKeysym
将名称转换为键符,因此":"
将不起作用,而必须使用"colon"
。
Keycodes are not standard (keyboard layouts vary), hence keysyms are used and are defined in <X11/keysymdef.h>
. 键盘代码不是标准的(键盘布局各不相同),因此使用了键盘符号,它们在<X11/keysymdef.h>
中定义。
The best you can do, is to use XKeysymToKeycode
with XK_a and XK_colon. 最好的办法是将XKeysymToKeycode
与XK_a和XK_colon一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.