bug report/suggested temp. patch: handling bursts of sent keys

Mark Lillibridge mark.lillibridge@hp.com
Sat Jan 23 22:02:00 GMT 2010

Dennis wrote:
> Hi Mark.
> I am a bit new to this list, but not THAT new to programming.  If you don't
> know how many keystrokes you need to have a buffer for, then you have 2
> choices:
> 1.  Have a ridiculously huge buffer.
> 2.  Setup a dynamic array.
> Using a 25000 character buffer seems like overkill.  But mieq.c is probably
> reading just from the Operating Systems' keyboard buffer.
> You may need to write an input function to feed mieq.c and somehow link to
> it.  Sadly, that level of coding is beyond my abilities.

    Option 1 would be a temporary patch.  Browsing through the source
code, keypresses/releases come one at a time in via window messages to
the following routine in hw/xwin/winwndproc.c:

     * Called by winWakeupHandler
     * Processes current Windows message
    winWindowProc (HWND hwnd, UINT message, 
                   WPARAM wParam, LPARAM lParam)
        case WM_SYSKEYDOWN:
        case WM_KEYDOWN:
          if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
          /* Translate Windows key code to X scan code */
          winTranslateKey (wParam, lParam, &iScanCode);
          /* Ignore repeats for CapsLock */
          if (wParam == VK_CAPITAL)
            lParam = 1;
          /* Send the key event(s) */
          for (i = 0; i < LOWORD(lParam); ++i)
            winSendKeyEvent (iScanCode, TRUE);
          return 0;

winSendKeyEvent in turn lives in hw/xwin/winkeybd.c:

     * Take a raw X key code and send an up or down event for it.
     * Thanks to VNC for inspiration, though it is a simple function.
    winSendKeyEvent (DWORD dwKey, Bool fDown)
      EventListPtr events;
      int i, nevents;
       * When alt-tabing between screens we can get phantom key up messages
       * Here we only pass them through it we think we should!
      if (g_winKeyState[dwKey] == FALSE && fDown == FALSE) return;
      /* Update the keyState map */
      g_winKeyState[dwKey] = fDown;
      nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRele
    ase, dwKey + MIN_KEYCODE);
      for (i = 0; i < nevents; i++)
        mieqEnqueue(g_pwinKeyboard, events[i].event);
    #if CYGDEBUG
      ErrorF("winSendKeyEvent: dwKey: %d, fDown: %d, nEvents %d\n",
              dwKey, fDown, nevents);

Note the call to mieqEnqueue there.  

    I am not a Windows programmer.  Can someone tell me if it's okay for
winWindowProc to block?  In particular, could we make it block until the
mieq queue is not full?

- Mark

Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

More information about the Cygwin-xfree mailing list