To cobble off of the previous if the desire is to create a custom button whose action method can distinguish down presses from releases, try adding the property isPressed
to it, and the following code:
(void)mouseDown:(NSEvent *)event
{
self.isPressed = true;
[super mouseDown:event];
self.isPressed = false;
[self.target performSelector:self.action withObject:self];
}
The custom button must be set to send actions per:
[self.button sendActionOn: NSLeftMouseDownMask | NSLeftMouseUpMask];
Without this, the action method is not called until the button is released.
In the action method, isPressed
can be queried. e.g:
int state = (int)[sender isPressed];
An annoying but harmless "Feature" of this is that the action method is called twice when the button is released: once from inside NSButton
with isPressed
still true. (This should be ignored.) The second time from custom button's performSelector
method, with isPressed
false.
Any comments on if this is likely to work on future releases?