Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.8.0
-
None
-
Windows 10 winrt x86
-
-
32b92b9e21a7a684fa9c23b881cda5b913699574
Description
I've come across an issue where the value returned by QWinRTScreen::keyboardModifiers() does not actually reflect the active pressed keyboard modifiers.
I've been able to reproduce by doing the following:
1. Run the attached qml demo app
2. Press and hold shift key for 1 sec
3. Then press another key e.g. m
On the first press of 'm' when shift is held down, the logged modifier value is '0', if you press 'm' again whilst shift is still held down. The correct modifier value is reported.
I think the issue is down to GetAsyncKeyState() in QWinRTScreen::keyboardModifiers() not returning the correct key state.
If I change the implementation of QWinRTScreen::keyboardModifiers() to:
Qt::KeyboardModifiers QWinRTScreen::keyboardModifiers() const { Q_D(const QWinRTScreen); Qt::KeyboardModifiers mods; CoreVirtualKeyStates mod; d->coreWindow->GetKeyState(VirtualKey_Shift, &mod); if (mod & CoreVirtualKeyStates_Down) mods |= Qt::ShiftModifier; d->coreWindow->GetKeyState(VirtualKey_Menu, &mod); if (mod & CoreVirtualKeyStates_Down) mods |= Qt::AltModifier; d->coreWindow->GetKeyState(VirtualKey_Control, &mod); if (mod & CoreVirtualKeyStates_Down) mods |= Qt::ControlModifier; d->coreWindow->GetKeyState(VirtualKey_LeftWindows, &mod); if (mod & CoreVirtualKeyStates_Down) { mods |= Qt::MetaModifier; } else { d->coreWindow->GetKeyState(VirtualKey_RightWindows, &mod); if (mod & CoreVirtualKeyStates_Down) mods |= Qt::MetaModifier; } return mods; }
Then for me it seems the correct modifier state is returned as expected.