好吧,如果你在X11之下并想要获得kbd,你需要抓住它.
如果你不是,我唯一的好答案是来自终端的ncurses.
以下是您从键盘获取所有内容并再次发布的方法:
/* Demo code, needs more error checking, compile
* with "gcc nameofthisfile.c -lX11".
/* weird formatting for markdown follows. argh! */
#include< X11 / Xlib.h>
int main(int argc, char **argv)
{
Display *dpy;
XEvent ev;
char *s;
unsigned int kc;
int quit = 0;
if (NULL==(dpy=XOpenDisplay(NULL))) {
perror(argv[0]);
exit(1);
}
/*
* You might want to warp the pointer to somewhere that you know
* is not associated with anything that will drain events.
* (void)XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, x, y);
*/
XGrabKeyboard(dpy, DefaultRootWindow(dpy),
True, GrabModeAsync, GrabModeAsync, CurrentTime);
printf("KEYBOARD GRABBED! Hit 'q' to quit!\n"
"If this job is killed or you get stuck, use Ctrl-Alt-F1\n"
"to switch to a console (if possible) and run something that\n"
"ungrabs the keyboard.\n");
/* A very simple event loop: start at "man XEvent" for more info. */
/* Also see "apropos XGrab" for various ways to lock down access to
* certain types of info. coming out of or going into the server */
for (;!quit;) {
XNextEvent(dpy, &ev);
switch (ev.type) {
case KeyPress:
kc = ((XKeyPressedEvent*)&ev)->keycode;
s = XKeysymToString(XKeycodeToKeysym(dpy, kc, 0));
/* s is NULL or a static no-touchy return string. */
if (s) printf("KEY:%s\n", s);
if (!strcmp(s, "q")) quit=~0;
break;
case Expose:
/* Often, it's a good idea to drain residual exposes to
* avoid visiting Blinky's Fun Club. */
while (XCheckTypedEvent(dpy, Expose, &ev)) /* empty body */ ;
break;
case ButtonPress:
case ButtonRelease:
case KeyRelease:
case MotionNotify:
case ConfigureNotify:
default:
break;
}
}
XUngrabKeyboard(dpy, CurrentTime);
if (XCloseDisplay(dpy)) {
perror(argv[0]);
exit(1);
}
return 0;
}
从终端运行此命令,所有kbd事件都应该点击它.我在Xorg下测试它
但它使用了古老而稳定的Xlib机制.
希望这可以帮助.
小心翼翼地抓住X.当你刚接触它们时,有时它会很好
想要开始一个时间延迟的过程,当你的时候,它会解开你的服务器
测试代码并让它每隔几分钟就坐下来运行一次.
它节省了必须杀死或切换远离服务器到外部重置状态.
从这里开始,我将留给您决定如何复用渲染.读
开始使用XGrabKeyboard docs和XEvent文档.
如果您在屏幕角落露出小窗户,则可能会卡住
将指针指向一个角以选择一个控制器. XWarpPointer可以
从代码中将指针推送到其中一个.
还有一点:你也可以抓住指针和其他资源.如果您在前面的盒子上运行了一个控制器,则可以使用键盘和鼠标输入在具有不同渲染器的打开套接字之间切换.您不应该再使用这种方法将输出窗口的大小调整为低于全屏幕.通过更多的工作,你可以使用SHAPE和COMPOSITE扩展将alpha混合叠加层放在顶部以获得一个很好的叠加功能以响应用户输入(这可能算作镀金百合).