tags:

views:

57

answers:

0

I have the following code. For some reason the key-related events aren't firing. FocusChanged is firing fine. I'm using Gnome. Could it be that Gnome's intercepting these and not passing them through? I mean, some people may regard this as a security risk (keylogger), so it's a possibility.

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);

            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)
            XSelectInput(dpy, w = GetCurrWindow(dpy),
                FocusChangeMask|KeyPressMask|KeyReleaseMask);

    }
}