我正在尝试让我的C应用程序在按下ctrl + k按钮时执行某些任务(或者CTRL SHIFT K还不确定),文档有点sccarce但我能够找到一个cpp示例并尝试过模仿那段代码:
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 pressed\n");
}
我理解按键是由XGrabKey函数捕获的,xnext事件读取事件并存储在ev中,我将类型与按键Xevent类型进行比较,消息未打印,我试过ctrl + k和shift + k和ctrl + shift + k
答案 0 :(得分:1)
您永远不会调用XNextEvent()
,因为while(0)
循环永远不会运行。 (你可能意味着while(1)
!)