Flags on onKeyDown?
-
@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 4The masks are constants, which are set to some convenient values:
# I just made these up 001 = CONSTRAIN_MASK 010 = ALT_MASK 100 = COPY_MASKSo if the flag is decimal value 7:
111 <- decimal 7In 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement