problem with dead keys (acute, diaeresis, etc) c++

落花浮王杯 提交于 2019-12-13 16:00:55

问题


I'm currently writing my own virtual keyboard for linux using the X11 lib and i just can't find the way to simulate a KeyPress event of any dead keys. I'd tried , for example, to write "á" using the asigned macro, which is XK_aacute, and nothing happens. later i'd tried to send XK_acute (the acute accent macro) and then XK_a, and again, nothing happens :(

In the KDE virtual Keyboard "Kvkbd" it's possible to do this, so i downloaded the source code, but it only supports the english keyboard layout

Here is my test code:

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
#include <iostream>

int main(){
 Display *display;
 unsigned int keycode;
 unsigned int keycode1;
 display = XOpenDisplay(NULL);

 keycode = XKeysymToKeycode(display, XK_aacute); 
 XTestFakeKeyEvent(display, keycode, True, 0);
 XTestFakeKeyEvent(display, keycode, False, 0);

 keycode1 = XKeysymToKeycode(display, XK_acute);
 XTestFakeKeyEvent(display, keycode1, True, 0);


 keycode = XKeysymToKeycode(display, XK_a);
 XTestFakeKeyEvent(display, keycode, True, 0);
 XTestFakeKeyEvent(display, keycode, False, 0);

 XTestFakeKeyEvent(display, keycode1, False, 0);


 keycode = XKeysymToKeycode(display, XK_D);
 XTestFakeKeyEvent(display, keycode, True, 0);
 XTestFakeKeyEvent(display, keycode, False, 0);
 XFlush(display);
}

Any help or idea will be much apreciated


回答1:


i just figured out ¬¬

#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <iostream>

int main(){
 Display *display;
 unsigned int keycode;
 unsigned int keycode1;
 display = XOpenDisplay(NULL);

 keycode1 = XKeysymToKeycode(display, XK_dead_acute);
 XTestFakeKeyEvent(display, keycode1, true, 0);


 keycode = XKeysymToKeycode(display, XK_A);
 XTestFakeKeyEvent(display, keycode, true, 0);
 XTestFakeKeyEvent(display, keycode, false, 0);

 XTestFakeKeyEvent(display, keycode1, false, 0);

 XFlush(display);
}

i was using the wrong macro



来源:https://stackoverflow.com/questions/2391476/problem-with-dead-keys-acute-diaeresis-etc-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!