Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-58750

winrt: Keyboard modifier key state not always correct.

XMLWordPrintable

    • WinRT
    • 32b92b9e21a7a684fa9c23b881cda5b913699574

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            owolff Oliver Wolff
            rupert_d Rupert Daniel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes