栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

监听键盘事件而不在X11中消耗它们-键盘挂接

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

监听键盘事件而不在X11中消耗它们-键盘挂接

这是我的例子

#include <X11/X.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <stdio.h>#include <ctype.h>int main (){    Display* d = XOpenDisplay(NULL);    Window root = DefaultRootWindow(d);    Window curFocus;    char buf[17];    KeySym ks;    XComposeStatus comp;    int len;    int revert;    XGetInputFocus (d, &curFocus, &revert);    XSelectInput(d, curFocus, KeyPressMask|KeyReleaseMask|FocusChangeMask);    while (1)    {        XEvent ev;        XNextEvent(d, &ev);        switch (ev.type)        { case FocusOut:     printf ("Focus changed!n");     printf ("Old focus is %dn", (int)curFocus);     if (curFocus != root)         XSelectInput(d, curFocus, 0);     XGetInputFocus (d, &curFocus, &revert);     printf ("New focus is %dn", (int)curFocus);     if (curFocus == PointerRoot)         curFocus = root;     XSelectInput(d, curFocus, KeyPressMask|KeyReleaseMask|FocusChangeMask);     break; case KeyPress:     printf ("Got key!n");     len = XLookupString(&ev.xkey, buf, 16, &ks, &comp);     if (len > 0 && isprint(buf[0]))     {         buf[len]=0;         printf("String is: %sn", buf);     }     else     {         printf ("Key is: %dn", (int)ks);     }        }    }}

它不可靠,但在大多数情况下都有效。(它显示的是我正在此框中输入的键)。您可能会调查为什么有时会失败;)原则上它也不能显示热键。热键是获取的密钥,只有一个客户端可以获取获取的密钥。除了加载为此目的而设计的特殊X11扩展(例如XEvIE)以外,这里绝对不能做任何事情。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/397558.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号