That should about work, comparing the code to how plwm grabs keys.  Are you listening for X events in the busy loop?  Unless you do that or call d.flush(), the grab_key request won't be sent to the X server and the key thus not grabbed either.  X looks like a plain API, but it is really fully asynchronous below the high-level function calls exposed by python-xlib.


On 8 April 2010 06:07, Chris Dekter <> wrote:
Hi guys,

I am trying a simple experiment to see if I can grab a certain
key/modifier combo to ensure no other application can receive this
combo (Super+d):

from Xlib import X, XK, display

d = display.Display()
root = d.screen().root
keycode = d.keysym_to_keycode(ord('d'))
root.grab_key(keycode, X.Mod4Mask, True, X.GrabModeAsync, X.GrabModeAsync)
(busy loop, followed by relevant clenaup code)

As far as I can tell, root.grab_key() does nothing. I have checked
that on my keymap Super is mapped to Mod4. I am basing this code on
examples I've found online using the regular C Xlib that, according to
their authors, do work.

Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
python-xlib-users mailing list