@ittayd said:
What is the meaning of the values of the flags parameter to the key callback methods in a tool?
Each bit in a bitfield represents a boolean switch for some feature.
In this case, is it whether a certain key's flag is sent to an onKey... callback.
To test whether whatever virtual keycode (that you got in the key
argument,) is also associated with one of the "modifier" keys (or mouse buttons,) you test the flags
bitfield against the desired bitmask constant (listed at the top of the Tools class documentation page,) using the bitwise AND ( &
) method.
If the result is 0
then that modifier key was not associated with the key
.
If the result is non- 0
(usually the value of the mask constant,) then that modifier key WAS associated with the key
.
This is accomplished because the &
operation ignores all bits in the bitfield that are unset (0) in the mask argument. (Only that bit that you are testing for is set to 1 in the mask.)
See wikipedia:
http://en.wikipedia.org/wiki/Mask_(computing)#Querying_the_status_of_a_bit
Was the SHIFT modifier associated with the key
argument ?
flags & CONSTRAIN_MODIFIER_MASK != 0
Was the Alt/Option on Mac, CTRL on PC modifier associated with the key
argument ?
flags & COPY_MODIFIER_MASK != 0
Was the Command on Mac, ALT on PC modifier associated with the key
argument ?
flags & ALT_MODIFIER_MASK != 0
The mousekeys modifier constants are:
MK_ALT, MK_COMMAND, MK_CONTROL, MK_LBUTTON, MK_MBUTTON, MK_RBUTTON, MK_SHIFT
It may help you to wrap them up into methods with names that make sense to you:
ie:
def mask_has_shift?(flags)
flags & CONSTRAIN_MODIFIER_MASK != 0
end
... etc.
BTW, all the virtual key codes and modifier mask constants are global (the API defines them at the toplevel.)
![:nerd_face: π€](https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f913.png?v=ortm2mm07uk)