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 开发者_C百科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
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
精彩评论