简体   繁体   English

X11 Shift + Tab 键符?

[英]X11 Shift + Tab keysym?

How to detect Shift + Tab in Xlib ?如何在Xlib中检测Shift + Tab I'm able to match KeySym with XK_Tab , but it's not matching while holding shift to then check for ev->state & ShiftMask , so I'm kind of lost.我能够将KeySymXK_Tab匹配,但它在按住 shift 键时不匹配,然后检查ev->state & ShiftMask ,所以我有点迷路了。

SOLUTION:解决方案:

Thanks to Erdal Küçük's answer I was able to come up with the following function that detects Shift + Tab:感谢 Erdal Küçük 的回答,我能够想出以下 function 来检测 Shift + Tab:

int detectShiftTab(XKeyEvent *xkey) {
    return XLookupKeysym(xkey, 0) == XK_Tab && xkey->state & ShiftMask;
}

With a simple test, i realized that the ShiftMask is not reported on a KeyPress of the Shift key.通过简单的测试,我意识到ShiftMask没有在 Shift 键的KeyPress上报告。 Other than that, the ShiftMask is always set.除此之外,始终设置ShiftMask

int main()
{
    Display *dpy = XOpenDisplay(NULL);
    
    Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 640, 480, 0, 0, 0);

    XSetWindowAttributes attr = { .event_mask = (KeyPressMask | KeyReleaseMask) };
    XChangeWindowAttributes(dpy, win, CWEventMask, &attr);

    XMapWindow(dpy, win);

    while (1) {
        XEvent evt;
        XNextEvent(dpy, &evt);

        switch (evt.type) {

            case KeyPress:
            printf(
                "key press: %s shiftmask: %d\n", 
                XKeysymToString(XLookupKeysym(&evt.xkey, 0)), 
                (evt.xkey.state & ShiftMask) == ShiftMask
            );
            break;

            case KeyRelease:
            printf(
                "key release: %s shiftmask: %d\n", 
                XKeysymToString(XLookupKeysym(&evt.xkey, 0)), 
                (evt.xkey.state & ShiftMask) == ShiftMask
            );
            break;

        }
    }

    return 0;
}

I get the following output (typing Shift + Tab):我得到以下 output(键入 Shift + Tab):

key press:   Shift_L shiftmask: 0
key press:   Tab shiftmask: 1
key release: Tab shiftmask: 1
key release: Shift_L shiftmask: 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM