【发布时间】:2010-01-20 10:34:47
【问题描述】:
如果您在启用 AutoRepeat 时按住 X11 中的某个键,您会不断收到 KeyPress 和 KeyRelease 事件。我知道 AutoRepeat 可以使用函数 XAutoRepeatOff() 禁用,但这会改变整个 X 服务器的设置。有没有办法为单个应用程序禁用 AutoRepeat 或忽略重复的击键?
我正在寻找的是当一个键被按下时的单个 KeyPress 事件和一个键被释放时的单个 KeyRelease 事件,而不干扰 X 服务器的自动重复设置。
这是一个让你开始的小例子(主要来自Beginner Xlib Tutorial):
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
Display *dis;
Window win;
XEvent report;
int main ()
{
dis = XOpenDisplay (NULL);
// XAutoRepeatOn(dis);
win = XCreateSimpleWindow (dis, RootWindow (dis, 0), 1, 1, 500, 500,
0, BlackPixel (dis, 0), BlackPixel (dis, 0));
XSelectInput (dis, win, KeyPressMask | KeyReleaseMask);
XMapWindow (dis, win);
XFlush (dis);
while (1)
{
XNextEvent (dis, &report);
switch (report.type)
{
case KeyPress:
fprintf (stdout, "key #%ld was pressed.\n",
(long) XLookupKeysym (&report.xkey, 0));
break;
case KeyRelease:
fprintf (stdout, "key #%ld was released.\n",
(long) XLookupKeysym (&report.xkey, 0));
break;
}
}
return (0);
}
【问题讨论】:
标签: keyboard x11 autorepeat