associatedEventsMask
The associated events mask of a mouse event.
Declaration
var associatedEventsMask: NSEvent.EventTypeMask { get }Discussion
This property pertains to mouse events. It’s used to determine whether the input device issuing the event can simultaneously issue events of type NSEvent.EventType.pressure. This can be useful if you need to determine whether to initiate or begin initiating a pressure-related action when a mouse event occurs.
For example, suppose you are writing a painting app that uses pressure to determine the size of brush stroke to apply. You can use associatedEventsMask to determine whether a mouse-click event is occurring simultaneously with a pressure event. If not, the user may not have pressure-sensitive hardware and you can apply a default size to the brush stroke.
Listing 1. Example usage of the associatedEventMask property
if (event.associatedEventMask & NSEventMaskPressure) {
self.pressure = 0; // Prepare for pressure events
} else if (event.subtype == NSTabletPointEventSubtype) {
self.pressure = event.pressure; // For tablets, the pressure value is embedded in the mouse event
} else {
self.pressure = 1; // The input device does not support pressure sensitivity, so default to full pressure
}