title: Ignore auto repeat in X11 applications
body: <p>If you press and hold a key in X11 while <em>AutoRepeat</em> is enabled, you continuously receive <strong>KeyPress</strong> and <strong>KeyRelease</strong> events.  I know that <em>AutoRepeat</em> can be disabled using the function <strong>XAutoRepeatOff()</strong>, but this changes the setting for the whole X server.  Is there a way to either disable <em>AutoRepeat</em> for a single application or to ignore repeated keystrokes? </p>
  
  <p>What I'm looking for is a single <strong>KeyPress</strong> event when a key is pressed and a single <strong>KeyRelease</strong> event when a key is released, without interfering with the X server's <em>AutoRepeat</em> setting.</p>
  
  <p>Here's a minimal example to get you going (mostly from the <a href="http://www.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html" rel="noreferrer">Beginner Xlib Tutorial</a>):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;X11/Xlib.h&gt;
  #include &lt;X11/Xutil.h&gt;
  #include &lt;X11/Xos.h&gt;
  #include &lt;X11/Xatom.h&gt;
  #include &lt;X11/keysym.h&gt;
  
  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, &amp;report);
        switch (report.type)
   {
   case KeyPress:
     fprintf (stdout, "key #%ld was pressed.\n",
       (long) XLookupKeysym (&amp;report.xkey, 0));
     break;
   case KeyRelease:
     fprintf (stdout, "key #%ld was released.\n",
       (long) XLookupKeysym (&amp;report.xkey, 0));
     break;
   }
      }
  
    return (0);
  }
  </code></pre>