I have the following:

XGrabButton(display, XKeysymToKeycode(display, XK_C), Mod1Mask | KeyPressMask, window, false, GrabModeAsync, GrabModeAsync);

The goal is to capture Alt+Shift+C so I can use the combination to close windows. This works unless I have another modifier active. For example, CapsLock, NumLock, ctrl, ect.

How can I tell it to ignore all the other modifiers?

1 Answer 1


I have found the best way to do this is to avoid specifying a modifier at all. Instead I use AnyModifier and check if the modifier I require is active using event.state in XButtonEvent:

XGrabKey(DISPLAY, XKeysymToKeycode(DISPLAY, XK_C), AnyModifier, frame, false, GrabModeAsync, GrabModeSync);

void WindowManager::OnKeyPress(const XKeyEvent& event)
    if(!(event.state & Mod1Mask))

    //Handle buttons...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .