[comp.windows.x] Grabbing keys

davis@3d.enet.dec.com (Peter Davis) (05/23/91)

I'm trying to write a program that will grab a few keys and handle events from
them.  This program will not have a window of its own, but I want it to grab
events from the specified keys regardless of where the focus is. NB: Before
anyone starts flaming about what a bad practice this is, it's just a hack
program that I'm going to run on my own system.

Anyway, I think it should be possible to just do something like:

Display *disp = XOpenDisplay (NULL);

XGrabKey (disp, XKeysymToKeycode (disp, XK_Left), AnyModifier,
	  RootWindow (disp, DefaultScreen (disp)),
	  True, GrabModeAsync, GrabModeAsync);

However, when I do this, the program crashes inside XNextEvent when I type
one of the grabbed keys.

Am I allowed to specify the root window as my grab_window?  Is there something
else I need to do to accomplish this?

Thanks.
-pd