title: Why use (bitwise) & when handling keyboard events involving multiple keys?
body: <p>Reading <a href="https://stackoverflow.com/questions/65127217/can-i-use-this-method-to-not-use-the-bitwise-operator">this Pygame question</a> made me wonder <em>why</em>, if I want to check whether the shift key is pressed (simultaneously with another key), I have to write something like</p>
  <pre class="lang-py prettyprint-override"><code>if event.key == K_s:
      if event.mod &amp; KMOD_SHIFT:
          ...
  </code></pre>
  <p>and in particular, while I do understand perfectly why this code fragment isn't equivalent to the other one in the question, I am wondering what the reason is for a bit-to-bit comparison, which seems a bit weird in this context, where we're basically just checking if two events occur at the same time.</p>
  <p>The value of <code>mod</code> <em>seems</em> to always be 1 when shift is pressed, and at least at a first glance <a href="https://buildmedia.readthedocs.org/media/pdf/pygame/latest/pygame.pdf" rel="nofollow noreferrer">the docs</a> seem not to provide any explanation for using <code>&amp;</code>.</p>
  <p><strong>Edit</strong>: this has been marked as a duplicate of <a href="https://stackoverflow.com/questions/1746613/bitwise-operation-and-usage">this other question</a> but it obviously isn't, as</p>
  <ul>
  <li>this is specific to pygame</li>
  <li>I had already taken a look and it was not at all as helpful as the answer I got, as the answers mostly deal with the more theorical aspects of the question</li>
  </ul>