使用Xlib的XsendEvent发送关键事件(不使用XTEST)

时间:2019-03-22 09:04:34

标签: x11

我想将带有Shift修饰符的'a'发送到一个窗口(带有windowId wid),并期望它发送 大写字母“ A”。但是,它总是发送小写字母“ a”。我将shift修饰符应用于按键事件的状态。 我在这里想念什么?

    XKeyEvent xkpe;
    xkpe.type = KeyPress;
    xkpe.display = disp;
    xkpe.window = wid;
    xkpe.root = root;
    xkpe.subwindow = None;
    xkpe.time = CurrentTime;
    xkpe.x = 0;
    xkpe.y = 0;

    Window dummy;
    unsigned int mask,dummyUInt;
    int ret,dummyInt;
    ret = XQueryPointer(xkpe.display, xkpe.window, &dummy, &dummy,
        &dummyInt, &dummyInt, &dummyInt, &dummyInt, &mask);

    if(ret == 0){
        qDebug() << "XTranslateCoordinates unsuccessfull returning early";
        return;
    }

    xkpe.state = mask | ShiftMask;
    xkpe.keycode = XKeysymToKeycode(xkpe.display,XK_a);
    xkpe.same_screen = True;

    ret = XSendEvent(xkpe.display, wid, False, KeyPressMask | KeyReleaseMask, (XEvent *)&xkpe);

让我知道工作代码是否有助于回答这个问题。

0 个答案:

没有答案