XKeysymToKeycode和键盘布局

问题描述 投票:0回答:1

我正在尝试使用功能XKeysymToKeycode将击键发送到活动的x11应用程序。该功能有效,但使用的是英文键盘。我的电脑本地化为意大利语。现在,我必须发送例如意大利语键盘中定义的字符“à”。我该如何发送?

x11
1个回答
0
投票

我一直在努力解决同一问题。似乎:

  1. [多重布局功能被实现为组,对于与美国键盘不同的字符,您的IT布局部分位于组1中,而对于某些不变键(例如,返回/输入),您的IT布局位于组0中。
  2. XKeysymToKeycode不在乎组,它只选择第一个匹配项。

您可以手动进行as the clutter guys did。或结合使用gdk和X:

//char *oksym ="KP_Enter";
char *oksym ="at";
gboolean orv;
guint okeyval;
GdkKeymapKey *okeys;
gint on_keys;
GdkKeymap *okeymap;
GdkDisplay *odisplay;

XkbGetState(display, XkbUseCoreKbd, &xkbState);
printf("Active group would be %d\n",xkbState.group);

odisplay = gdk_display_get_default();
okeymap = gdk_keymap_get_for_display(odisplay);
okeyval = gdk_keyval_from_name(oksym);
if(okeyval == GDK_KEY_VoidSymbol){
    printf("GDK keyval GDK_KEY_%s is unknown\n",oksym);
    exit(-1);
}
orv = gdk_keymap_get_entries_for_keyval(okeymap, okeyval, &okeys, &on_keys);
printf("The following hardware keys will produce keyval GDK_KEY_%s(%d):\n",oksym,okeyval);
for(int i = 0; i < on_keys; i++){
    /*Groups seems to be used to manage multiple keyboard layouts (at least using MATE) 
     * instead/on top of their orignal meaning. Getting the active layout seems to be 
     * acheivable using XkbGetState. Some keys seems to be shared/stay on group 0, example 
     * Return/Enter. So if there is more than one key bound to a keyval, we'll take the one
     * that matches the active group. If there is only one (i.e Enter/Return) we'll just take
     * it regardless of its group.
     * */
    if( okeys[i].group == xkbState.group || on_keys == 1)
        printf("\tkeycode: %d, group: %d, level: %d\n",okeys[i].keycode,okeys[i].group,okeys[i].level);
}
© www.soinside.com 2019 - 2024. All rights reserved.