AutoRepeatが有効なときに X11 でキーを押したままにすると、 KeyPressイベントとKeyReleaseイベントを継続的に受け取ります。関数XAutoRepeatOff()を使用してAutoRepeatを無効にできることは知っていますが、これにより X サーバー全体の設定が変更されます。単一のアプリケーションのAutoRepeatを無効にする方法、または繰り返されるキーストロークを無視する方法はありますか?
私が探しているのは、X サーバーのAutoRepeat設定に干渉することなく、キーが押されたときの単一のKeyPressイベントと、キーが離されたときの単一のKeyReleaseイベントです。
これは、あなたが始めるための最小限の例です (主に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);
}