From 7d2f9f3a0dd559a65841685aab08fcb5d119db77 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 Jun 2013 10:05:56 +0000 Subject: [PATCH] From Juan Manuel Alvarez, "When handling keyboard events on osgQt, if a key is kept pressed, multiple sequences of KEYDOWN -> KEYUP events are fired. This is because Qt auto repeats keyboard events, so multiple calls are made to GLWidget::keyPressEvent and GLWidget::keyReleaseEvent by Qt, and subsequently translated to OSG events. The way to solve this is ignoring key released auto repeated events (see http://qt-project.org/doc/qt-4.8/qkeyevent.html#isAutoRepeat), so multiple KEYDOWN events are fired, but only one KEYUP. I attach a modified osgQt/GraphicsWindowQt.cpp with this change." --- src/osgQt/GraphicsWindowQt.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/osgQt/GraphicsWindowQt.cpp b/src/osgQt/GraphicsWindowQt.cpp index 55358bcfc..ba0d8f199 100644 --- a/src/osgQt/GraphicsWindowQt.cpp +++ b/src/osgQt/GraphicsWindowQt.cpp @@ -269,9 +269,16 @@ void GLWidget::keyPressEvent( QKeyEvent* event ) void GLWidget::keyReleaseEvent( QKeyEvent* event ) { - setKeyboardModifiers( event ); - int value = s_QtKeyboardMap.remapKey( event ); - _gw->getEventQueue()->keyRelease( value ); + if( event->isAutoRepeat() ) + { + event->ignore(); + } + else + { + setKeyboardModifiers( event ); + int value = s_QtKeyboardMap.remapKey( event ); + _gw->getEventQueue()->keyRelease( value ); + } // this passes the event to the regular Qt key event processing, // among others, it closes popup windows on ESC and forwards the event to the parent widgets