Keypressed/Keyreleased events not reaching my code

Scott Sibley sisibley at gmail.com
Mon Nov 16 21:28:44 PST 2009


Hello. I'm writing an LCD controller, and one feature I'd like is the
ability to interact with an LCD via the keyboard. I have the following code,
but only the FocusOut/FocusIn events are firing.

static Window GetCurrWindow(Display *d) {
    Window foo;
    Window win;
    int bar;

    do{
        (void) XQueryPointer(d, DefaultRootWindow(d), &foo, &win,
            &bar, &bar, &bar, &bar, (unsigned int *)&bar);
    } while(win <= 0);
    return(win);
}

void PluginKeyboard::PluginPoll() {
    Display *dpy = XOpenDisplay(NULL);
    if(!dpy) {
        LCDError("PluginKeyboard: Unable to open display.");
        return;
    }

    Window w = GetCurrWindow(dpy);
    XSelectInput(dpy, w, FocusChangeMask|KeyPressMask|KeyReleaseMask);
    while(started_) {

        if(!XPending(dpy))
            continue;

        XEvent event;
        char str[256+1];
        KeySym ks;
        char keycode;
        int c;

        XNextEvent(dpy, &event);

        if(event.type == KeyPress) {
            c = XLookupString((XKeyEvent *)&event, str, 256, &ks, NULL);

            LCDError("KeyPressed");
            if(c!=0)
                continue;

            keycode = XKeysymToKeycode(dpy, ks);

            emit _KeyPressed(keycode);
            LCDError("Keypressed: %d", keycode);
        }

        if(event.type == KeyRelease) {
            c = XLookupString((XKeyEvent *)&event, str, 256, &ks, NULL);

            if(c!=0)
                continue;

            keycode = XKeysymToKeycode(dpy, ks);

            emit _KeyReleased(keycode);
        }

        if(event.type == FocusOut) {
            LCDError("FocusOut");
            XSelectInput(dpy, w = GetCurrWindow(dpy),
                FocusChangeMask|KeyPressMask|KeyReleaseMask);
        }

    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20091116/d92c1e0a/attachment.html>


More information about the xorg mailing list