@chris fullmer said:
I don't quite understand what that means. What is bitwise?
Think in binary, then compare them column for column. It's a logical, bit-to-bit comparison.
5 in binary is 101
6 in binary is 110
5 & 6 is; logical AND each column (bit position)
Columns
________________
| 1 | 0 | 1 <- decimal 5
| and | and | and
| 1 | 1 | 0 <- decimal 6
=================
1 0 0
so 101 & 110 = 100 <- decimal 4
The masks are constants, which are set to some convenient values:
# I just made these up
001 = CONSTRAIN_MASK
010 = ALT_MASK
100 = COPY_MASK
So if the flag is decimal value 7:
111 <- decimal 7
In order to check the CONSTRAIN_MASK, you logical AND the CONSTRAIN_MASK with the flag value:
111 <- flag value decimal 7
& 001 <- contain mask constant
======
001 <- CONSTRAIN_MASK set true
or in real ruby as Thomas wrote;
contrain_key_down = ((flags & CONSTRAIN_MODIFIER_MASK) == CONSTRAIN_MODIFIER_MASK)
copy_key_down = ((flags & COPY_MODIFIER_MASK) == COPY_MODIFIER_MASK)
alt_key_down = ((flags & ALT_MODIFIER_MASK) == ALT_MODIFIER_MASK)
Although Adam B might know a clever way to decode them all in one elegant statement.