I don’t fully understand the following code. Isn’t NSCommandKeyMask a fixed integer ?
Then isn’t the second part of the condition always true ?
For instance, isn’t the same to: ([theEvent modifiedFlags] & 1)
if ([theEvent modifierFlags] & NSCommandKeyMask) {
NSLog(@"Alt key Down (again)!");
}
thanks
It absolutely is–but I think you’re confusing the boolean and operator with the bitwise and operator. Here, they’re performing a bitwise operation on
modifierFlags. Read more here.Basically, it performs a calculation on each individual binary digit. In the case of
&, it results in1if both digits are1, and0otherwise. Example:modifierFlagssets each binary place based on some modifier flag, then each mask contains a single one in its appropriate place. Thus, performing this operation results in 0 if that flag is not set, and some non-zero value if that flag is set. That’s why that if statement works.