Reading this Pygame question made me wonder why, if I want to check whether the shift key is pressed (simultaneously with another key), I have to write something like
if event.key == K_s:
if event.mod & KMOD_SHIFT:
...
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.
The value of mod
seems to always be 1 when shift is pressed, and at least at a first glance the docs seem not to provide any explanation for using &
.
Edit: this has been marked as a duplicate of this other question but it obviously isn't, as
- this is specific to pygame
- 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