Windows: Clear key recorder when application becomes inactive.

When keys are pressed and the application becomes inactive before
they are released, the stored state becomes inconsistent.

Task-number: QTBUG-49930
Change-Id: Ide86b1d9052df060f30f7c02b81a4f2ae15d28e7
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-12-14 12:02:29 +01:00
parent 69839e55c1
commit ac5c2aaf35

View File

@ -86,10 +86,15 @@ QT_BEGIN_NAMESPACE
The code originates from \c qkeymapper_win.cpp.
*/
static void clearKeyRecorderOnApplicationInActive(Qt::ApplicationState state);
QWindowsKeyMapper::QWindowsKeyMapper()
: m_useRTLExtensions(false), m_keyGrabber(0)
{
memset(keyLayout, 0, sizeof(keyLayout));
QGuiApplication *app = static_cast<QGuiApplication *>(QGuiApplication::instance());
QObject::connect(app, &QGuiApplication::applicationStateChanged,
app, clearKeyRecorderOnApplicationInActive);
}
QWindowsKeyMapper::~QWindowsKeyMapper()
@ -144,6 +149,12 @@ struct KeyRecorder
};
static KeyRecorder key_recorder;
static void clearKeyRecorderOnApplicationInActive(Qt::ApplicationState state)
{
if (state == Qt::ApplicationInactive)
key_recorder.clearKeys();
}
KeyRecord *KeyRecorder::findKey(int code, bool remove)
{
KeyRecord *result = 0;