title: QKeyEvent with multiple shift/control modifiers
body: <p>I have a USB device with 6 buttons that I am trying to use with my app. The document for the device lists the key mappings for each button. One of these button for example is said to map to Ctrl+Shift+F20.</p>
  
  <p>Coding this though does not work:</p>
  
  <p>The code I have inherited is:</p>
  
  <pre><code>void devControl::processKeyRelease(QKeyEvent *ke)
  {
      int key = ke-&gt;key();
  
      if (ke-&gt;modifiers() &amp; Qt::ShiftModifier &amp;&amp;
          ke-&gt;modifiers() &amp; Qt::ControlModifier)
      {
           if ( key = Qt::Key_F20 )
           {
               // Do somethings
           }
      }
  .
  .
  }
  </code></pre>
  
  <p>I used USBLyzer ( <a href="http://www.usblyzer.com/" rel="nofollow noreferrer">http://www.usblyzer.com/</a> ) and evtest on Linux ( <a href="https://www.systutorials.com/docs/linux/man/1-evtest/" rel="nofollow noreferrer">https://www.systutorials.com/docs/linux/man/1-evtest/</a> ) to check the data/keys being sent and found for this button the following:</p>
  
  <p><a href="https://i.stack.imgur.com/ND8Ou.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ND8Ou.png" alt="enter image description here"></a></p>
  
  <p>The raw value is <code>01 03 00 6F 00 00 00 00 00</code>.</p>
  
  <p>Looking at all the buttons data, they all exhibit the same behaviour in the the modifiers are repeated. </p>
  
  <p>My thought is to try this:</p>
  
  <pre><code>    if (ke-&gt;modifiers() &amp; Qt::ShiftModifier &amp;&amp;
          ke-&gt;modifiers() &amp; Qt::ControlModifier &amp;&amp;
          ke-&gt;modifiers() &amp; Qt::ShiftModifier &amp;&amp;
          ke-&gt;modifiers() &amp; Qt::ControlModifier)
  </code></pre>
  
  <p>But is this correct? I am waiting to try this in the morning when I go back in to work, but would appreciate advice form anyone who has seen this before.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>The above did not make a difference.
  I added some more debug as follows:</p>
  
  <pre><code>if (e-&gt;type() == QEvent::KeyPress) {
      QKeyEvent *eKey = static_cast&lt;QKeyEvent *&gt;(e);
      qDebug() &lt;&lt; "Key PRESS event " &lt;&lt; eKey-&gt;modifiers() &lt;&lt; Qt::Key(eKey-&gt;key());
  
  }
  </code></pre>
  
  <p>The results were:</p>
  
  <pre><code>Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ControlModifier) Qt::Key(Key_Control)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ControlModifier) Qt::Key(Key_Control)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ControlModifier) Qt::Key(Key_Control)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ControlModifier) Qt::Key(Key_Control)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ControlModifier) Qt::Key(Key_Control)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_Shift)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_Shift)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_Shift)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_Shift)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_Shift)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_F20)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_F20)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_F20)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_F20)
  Key PRESS event  QFlags&lt;Qt::KeyboardModifiers&gt;(ShiftModifier|ControlModifier) Qt::Key(Key_F20)
  </code></pre>
  
  <p>I need a way to know when the whole event or key combinations start and end for sure. Then I can accumulate the presses over the whole event and decide what button was pressed.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Decided to handle this by adding booleans to record when key Control, Shift or Alt are detected, and when a non-modifier is detected assume we have all the keys (true for this device) then execute the appropriate logic.</p>
  
  <p>This works now.</p>
  
  <p>bool _controlPressed;
  bool _shiftPressed;
  bool _altPressed;
  bool _action_Completed;</p>
  
  <p>These are set to false when a new button press is detected.</p>
  
  <p>Then each time OnKeyRelease is called:</p>
  
  <pre><code>if (key == Qt::Key_Control ){
      _action_Completed = false; // We expect one or more key
      _controlPressed = true;
      return;
  }  
  if (key == Qt::Key_Shift ) {
      _action_Completed = false;  // We expect one or more key
      _shiftPressed = true;
      return;
  }
  if (key == Qt::Key_Alt ){
      _action_Completed = false; // We expect one or more key
      _altPressed = true;
      return;
  }
  if ( _controlPressed &amp;&amp; _shiftPressed &amp;&amp; _altPressed  &amp;&amp; ! _action_Completed )
  {
      if (! mappedKey( key)) {
          return;
      }
  
      doCtrlShiftAlt( key);
      return;
  }
  if ( _controlPressed &amp;&amp; _shiftPressed  &amp;&amp; ! _action_Completed )
  {
      if (! mappedKey( key)) {
          return;
      }
  
      doCtrlShift( key);
      return;
  }
  if (  _shiftPressed   &amp;&amp; ! _action_Completed )
  {
      if (! mappedKey( key)) {
          return;
      }
  
      doShift( key);
      return;
  }
  
  if (! mappedKey( key)) {
      return;
  }
  
  if (  ! _action_Completed )
  {
      doNoMod( key);
  }
  </code></pre>