I’m trying to get my C application to execute certain tasks when the ctrl+k button is pressed(OR CTRL SHIFT K not sure yet), documentation is a bit sccarce but I was able to find a cpp example and tried to mimic that code:
Display* dpy = XOpenDisplay(0); Window root = DefaultRootWindow(dpy); XEvent ev; unsigned int modifiers = ControlMask | ShiftMask; int keycode = 45; int pointer_mode = GrabModeAsync; int keyboard_mode = GrabModeAsync; XGrabKey(dpy, keycode, modifiers, root, 0, pointer_mode, keyboard_mode); XSelectInput(dpy, root, KeyPressMask); while(0) { XNextEvent(dpy, &ev); if (ev.type == KeyPress) printf("key has been pressedn"); }
I understand the keypresses are captured by the XGrabKey function, the xnext event reads the event and storees that in ev, which I’m comparing the type to the keypress Xevent type, the message does not get printed, I’ve tried ctrl+k and shift+k and ctrl+shift+k
Advertisement
Answer
You’re never calling XNextEvent()
, because a while(0)
loop never runs. (What you probably meant was while(1)
!)