getting all kbd events

Nokan Emiro uzleepito at gmail.com
Tue Jul 7 22:51:26 PDT 2009


Hi,
The next simple program tries to subscribe to all keyboard events, and print
a short message on all received ones.  I expected to see the short message
on all keypresses, for example if I press 'a', 'b', ..., '1', '2', ...,  or
'F1', 'F2', etc.  But this program prints messages only on Alt, Control,
Shift, and Windows keys.  How can I change the XkbSelectEvents's parameters
to be messaged on all keypresses?

  XkbSelectEvents(display, XkbUseCoreKbd, XkbAllEventsMask,
XkbAllEventsMask);

THX, Uzlee


===================================================
                                         The program
===================================================


#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>

Display *display;
int screen;
int xkblib_event_code;

int my_error_handler(Display *display, XErrorEvent *e) {
        char message[255];
        XGetErrorText(display, e->error_code, message, sizeof(message));
        fprintf(stderr, "Xlib error [code: %d]: '%s'\n", e->error_code,
message);
        exit(2);
        return 0;
}

void event_loop() {
        XkbEvent event;

        XkbSelectEvents(display, XkbUseCoreKbd, XkbAllEventsMask,
XkbAllEventsMask);

        while (True) {
                XNextEvent(display, &event.core);
                fprintf(stderr, "event received\n");
        }
}

int main(int argc, char *argv[]) {
        int error_rtrn, reason_rtrn;

        display = XkbOpenDisplay(NULL, &xkblib_event_code, &error_rtrn,
NULL, NULL, &reason_rtrn);
        if (!display) {
                fprintf(stderr, "Cannot open display.\n");
                exit(1);
        }
        XSetErrorHandler(my_error_handler);
        screen = DefaultScreen(display);

        event_loop();

        return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20090708/2ff79eef/attachment.html>


More information about the xorg mailing list