tags:

views:

4

answers:

0

Hey all,

I'm trying to write a quick program that uses XRecord, and I am having difficulty setting it up to catch Button Presses. I get the first event, the XRecordStartOfData, but not any other events. Is there a problem with my code, or maybe my package set-up? I'm running Jaunty, and my xorg package is the most recent (1:7.4~5ubuntu18). Here's my code:

#include<iostream>
#include <X11/Xutil.h>
#include <X11/extensions/record.h>

using namespace std;

XRecordContext record_context;
Display *current_display;

void eventCallback(XPointer c, XRecordInterceptData *data){
    int *count = (int*) c;

    (*count)++;

    cout<<"Hello"<<endl;

    if((*count) > 10){
        XRecordDisableContext(current_display, record_context);
    }
}

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

    //Get the display, the clients, the record range,
    // and create the context.
    current_display = XOpenDisplay(0);

    XRecordClientSpec clients = XRecordAllClients;

    XRecordRange *ranges = XRecordAllocRange();
    ranges->device_events.first = KeyPress;
    ranges->device_events.last = KeyRelease;

    record_context = XRecordCreateContext(current_display, 0, 
                                          &clients, 1,
                                          &ranges,1);



    //Enable the context to begin recording.
    int count = 0;
    XRecordEnableContext(current_display, record_context, 
                        eventCallback, (char*) &count);


    //Close the display
    XCloseDisplay(current_display);
}