More consistent keyrelease messages

Hi Jules,

On linux, when a key is pressed for some time, the keyStateChanged / keyPressed callbacks are called repeatedly with a sequence “keyrelease/keypress” . On mac and windows, when a key is kept pressed, only “keypress” events happen. Here is a small patch that allows filtering the spurious keyrelease events of the linux version, in case you are interested, in juce_linux_Windowing.cpp :

[code]+ static bool keyReleaseMsgShouldBeIgnored(const XKeyEvent* keyReleaseEvent) {

  •  if (XPending(display)) {
  •    XEvent e;
  •    XPeekEvent(display, &e);
  •    // same timestamp + same keycode + keypress => this is an auto-repeat keyRelease/keyPress pair !
  •    if ((e.type == 2 /* KeyPress */) &&
  •        (e.xkey.keycode == keyReleaseEvent->keycode) &&
  •        (e.xkey.time == keyReleaseEvent->time)) {
  •      return true;
  •    }
  •  }
  •  return false;
  • }
  • void handleKeyReleaseEvent (const XKeyEvent* const keyEvent)
  •  if (keyReleaseMsgShouldBeIgnored(keyEvent)) return;


Great! Thanks very much!

Doesn’t that disable auto repeat too ?
You know, the feature where you press the spacebar and hold it down to insert multiple spaces.

It still works as expected because only the fake keyrelease events are filtered, the auto-repeat “keypress” messages are still taken into account.