Xkb:如何将键码转换为keysym【JAVA教程】

!
也想出现在这里? 联系我们
信息

Xkb:如何将键码转换为keysym,第1张

概述Xkb:如何将键码转换为keysym

我只是试图采取一个KeyCode和一个修饰符掩码,并将其转换为使用Xkb扩展名的KeySym。 我似乎无法弄清楚为什么这是行不通的。 它明显的修改不匹配,但我不知道为什么。 我甚至不知道我是否正确转换组。

#include <stdio.h> #include <stdlib.h> #include <X11/Xh> #include <X11/XKBlib.h> voID check(XkbDescPtr keyboard_map,KeyCode keycode,unsigned int mask) { //What the hell is diff between XkbKeyGroupInfo and XkbKeyNumGroups? unsigned char info = XkbKeyGroupInfo(keyboard_map,keycode); int num_groups = XkbKeyNumGroups(keyboard_map,keycode); int key_wIDth = XkbKeyGroupsWIDth(keyboard_map,keycode); //int num_syms = XkbKeyNumSyms(keyboard_map,keycode); //Get the group unsigned int group = 0; // What should this default to? switch (XkbOutOfRangeGroupAction(info)) { case XkbRedirectIntoRange: /* If the RedirectIntoRange flag is set,the four least significant * bits of the groups wrap control specify the index of a group to * which all illegal groups correspond. If the specifIEd group is * also out of range,all illegal groups map to Group1. */ printf(\”XkbRedirectIntoRangen\”); group = XkbOutOfRangeGroupInfo(info); if (group >= num_groups) { group = 0; } break; case XkbClampIntoRange: /* If the ClampIntoRange flag is set,out-of-range groups correspond * to the nearest legal group. Effective groups larger than the * highest supported group are mapped to the highest supported group; * effective groups less than Group1 are mapped to Group1 . For * example,a key with two groups of symbols uses Group2 type and * symbols if the global effective group is either Group3 or Group4. */ printf(\”XkbClampIntoRangen\”); group = num_groups – 1; break; case XkbWrAPIntoRange: /* If neither flag is set,group is wrapped into range using integer * modulus. For example,a key with two groups of symbols for which * groups wrap uses Group1 symbols if the global effective group is * Group3 or Group2 symbols if the global effective group is Group4. */ printf(\”XkbWrAPIntoRangen\”); default: printf(\”Defaultn\”); if (num_groups != 0) { group %= num_groups; } break; } printf(\”Group Info %d,%d,%dn\”,group,num_groups,key_wIDth); //printf(\”Mask Info %d,ShiftMask,LockMask,ControlMask,Mod1Mask,Mod2Mask,Mod3Mask,Mod4Mask,Mod5Mask); XkbKeyTypePtr key_type = XkbKeyKeyType(keyboard_map,keycode,group); KeySym keysym = NoSymbol; int i; for (i = 0; i < key_type->map_count; i++) { if (key_type->map[i].active && key_type->map[i].mods.mask == mask) { keysym = XkbKeySymEntry(keyboard_map,i,group); } } //printf(\”%sn\”,XKeysymToString(keysym)); printf(\”KeyCode: %dn\”,(int) keycode); printf(\”KeySym: %dn\”,(int) keysym); } int main(int argc,const char * argv[]) { display * display; //Try to attach to the default X11 display. display = XOpendisplay(NulL); if(display == NulL) { printf(\”Error: Could not open display!n\”); return EXIT_FAILURE; } //Get the map XkbDescPtr keyboard_map = XkbGetMap(display,XkbAllClIEntInfoMask,XkbUseCoreKbd); KeyCode keycode = 56; // b check(keyboard_map,ShiftMask | LockMask | ControlMask); //Close the connection to the selected X11 display. XClosedisplay(display); return EXIT_SUCCESS; }

linux的C – 获取locking键状态\’

如何检测在linux中的鼠标和键盘不活动

如果我发送一个WM_KEYDOWN消息(使用wndproc),计算机将按住键直到我发送WM_KEYUP?

插入到windows键盘缓冲区

Qtembedded式linux事件观察

经过大量的试验和错误,我终于弄清楚了。 XKeycodetoKeysym明显中断,并且没有为扩展索引定义索引值计算。

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <X11/Xh> #include <X11/XKBlib.h> KeySym KeyCodetoKeySym(display * display,unsigned int event_mask) { KeySym keysym = NoSymbol; //Get the map XkbDescPtr keyboard_map = XkbGetMap(display,XkbUseCoreKbd); if (keyboard_map) { //What is diff between XkbKeyGroupInfo and XkbKeyNumGroups? unsigned char info = XkbKeyGroupInfo(keyboard_map,keycode); unsigned int num_groups = XkbKeyNumGroups(keyboard_map,keycode); //Get the group unsigned int group = 0x00; switch (XkbOutOfRangeGroupAction(info)) { case XkbRedirectIntoRange: /* If the RedirectIntoRange flag is set,all illegal groups map to Group1. */ group = XkbOutOfRangeGroupInfo(info); if (group >= num_groups) { group = 0; } break; case XkbClampIntoRange: /* If the ClampIntoRange flag is set,a key with two groups of symbols uses Group2 type and * symbols if the global effective group is either Group3 or Group4. */ group = num_groups – 1; break; case XkbWrAPIntoRange: /* If neither flag is set,a key with two groups of symbols for which * groups wrap uses Group1 symbols if the global effective group is * Group3 or Group2 symbols if the global effective group is Group4. */ default: if (num_groups != 0) { group %= num_groups; } break; } XkbKeyTypePtr key_type = XkbKeyKeyType(keyboard_map,group); unsigned int active_mods = event_mask & key_type->mods.mask; int i,level = 0; for (i = 0; i < key_type->map_count; i++) { if (key_type->map[i].active && key_type->map[i].mods.mask == active_mods) { level = key_type->map[i].level; } } keysym = XkbKeySymEntry(keyboard_map,level,group); XkbFreeClIEntMap(keyboard_map,true); } return keysym; } int main(int argc,const char * argv[]) { display * display; //Try to attach to the default X11 display. display = XOpendisplay(NulL); if(display == NulL) { printf(\”Error: Could not open display!n\”); return EXIT_FAILURE; } KeyCode keycode = 56; // b unsigned int event_mask = ShiftMask | LockMask; KeySym keysym = KeyCodetoKeySym(display,event_mask); printf(\”KeySym: %sn\”,XKeysymToString(keysym)); //Close the connection to the selected X11 display. XClosedisplay(display); return EXIT_SUCCESS; }

从XKeycodetoKeysym的手册页:

The XKeycodetoKeysym function uses internal Xlib tables and returns the KeySym @R_403_5552@d for the specifIEd KeyCode and the element of the KeyCode vector. If no symbol is @R_403_5552@d,XKeycodetoKeysym returns NoSymbol. XKeycodetoKeysym predates the XKB extension. If you want to lookup a KeySym while using XKB you have to use XkbKeycodetoKeysym.

我没有看到你的示例代码。

阅读完整的手册页获取更多信息。

总结

以上是内存溢出为你收集整理的Xkb:如何将键码转换为keysym全部内容,希望文章能够帮你解决Xkb:如何将键码转换为keysym所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞85 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容