NSButton Up/Down Events

Shawn Erickson shawnce at gmail.com
Fri Feb 9 09:33:01 PST 2007


On 2/9/07, Brad Carter <bcarter at mac.com> wrote:

> I can't figure out how to do this in Cocoa.  I have subclassed
> NSButton and overridden mouseDown: and mouseUp and display this to
> NSLog confirming my success.  How do I tell what button was pressed
> in the mouseDown: method?  I can't find anything in NSEvent that
> would hint that this info would be passed as an NSEvent.  Here's my
> code below.

Oh I may have misread what you asked above... by "button" did you mean
mouse button or user interface button?

The reference documentation I linked earlier covers both questions but
in case of the former...

mouseDown:, mouseDragged:, and mouseUp: only happens if the "left"
(primary) mouse button is clicked. So you don't need to check event
type... getting the message implies that the primary button was
clicked.

rightMouseDown:, rightMouseDragged:, and rightMouseUp: only happen if
the "right" (secondary) mouse button is clicked.

All other buttons that the mouse may have come in via otherMouseDown:,
otherMouseDragged:, and otherMouseUp: messages and you would check
[event buttonNumber] to know which button on the mouse was clicked.

Finally note that scroll wheel events come in via scrollWheel:.

-Shawn


More information about the MacOSX-dev mailing list