here's sample code i found so far but unfortunately it doesn't work on keys that were hooked by other apps.
Code:
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h> // I include this to test return values the lazy way
#include <unistd.h> // So we got the profile for 10 seconds
#include <iostream>
#define NIL (0) // A name for the void pointer
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
// Get some colors
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, whiteColor, whiteColor);
// Grab F2 key with code 68 (experiment by yourself)
int F2_KEY = 68;
XGrabKey( dpy, F2_KEY, AnyModifier, w, true, GrabModeAsync, GrabModeAsync );
// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);
// Infinite loop ( hazard thing ;) )
for(;;) {
XEvent e;
XNextEvent(dpy, &e);
if (e.type == KeyPress )
{
printf( "F2 was pressed!!!\n" );
}
}
}