title: xlib XNextEvent checking if a key is held down
body: <p>I am using xlib to get keyboard input I want to simulate windows its getAsynckeystate() to check if a button is being pressed I tried using a timer to fix the result but its still broken. the function should always return true if 'z' is held down even if other keys are pressed or released at the same time (not working right now)</p>
  
  <p>Code below </p>
  
  <pre><code>bool KeyboardState::keyPressed(Display* d, Window curFocus,int revert, Window root) {
  XEvent ev;
  XNextEvent(d, &amp;ev);
  clock_t startTime;
  switch (ev.type) {
      case FocusOut:
          if (curFocus != root)
              XSelectInput(d, curFocus, 0);
  
          XGetInputFocus(d, &amp;curFocus, &amp;revert);
          printf("New focus is %d\n", (int) curFocus);
  
          if (curFocus == PointerRoot)
              curFocus = root;
  
          XSelectInput(d, curFocus, KeyReleaseMask | FocusChangeMask | KeyPressMask);
          break;
  
      case KeyPress:
          ks = XLookupKeysym(&amp;(ev.xkey), 0);
  
          if (ks == XK_z) {
  
              keyState = true;
              startTime = clock();
          }
          break;
      case KeyRelease:
          if(ks == XK_z &amp;&amp; startTime - clock() &gt; 0){
  
          ks = XLookupKeysym(&amp;(ev.xkey), 0);
              keyState = false;
          }
  }
  return keyState;
  }
  </code></pre>