diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 4c0b94e6e7aba5827cf65ddeb55499a98e58da50..c5dff60114398b3e7030dff76f89fb3883eff16f 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -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;