keyboard - Ignore auto repeat in X11 applications -


if press , hold key in x11 while autorepeat enabled, continuously receive keypress , keyrelease events. know autorepeat can disabled using function xautorepeatoff(), changes setting whole x server. there way either disable autorepeat single application or ignore repeated keystrokes?

what i'm looking single keypress event when key pressed , single keyrelease event when key released, without interfering x server's autorepeat setting.

here's minimal example going (mostly 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 pressed.\n",      (long) xlookupkeysym (&report.xkey, 0));    break;  case keyrelease:    fprintf (stdout, "key #%ld released.\n",      (long) xlookupkeysym (&report.xkey, 0));    break;  }     }    return (0); } 

when receive key release , next event key press of same key combination, it's auto-repeat , key wasn't acutally released. can use code peek next event

if (event->type == keyrelease && xeventsqueued(disp, queuedafterreading)) {   xevent nev;   xpeekevent(disp, &nev);    if (nev.type == keypress && nev.xkey.time == event->xkey.time &&       nev.xkey.keycode == event->xkey.keycode)   {     /* key wasn’t released */   } } 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -