sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Flags on onKeyDown?

    Scheduled Pinned Locked Moved Developers' Forum
    21 Posts 8 Posters 1.8k Views 8 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      @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.

      Hi

      1 Reply Last reply Reply Quote 0
      • 1
      • 2
      • 2 / 2
      • First post
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement