NSButton Up/Down Events
Brad Carter
bcarter at mac.com
Fri Feb 9 19:29:26 PST 2007
I got this to work. Below is the code I used. I didn't use a
subclass like I was originally trying to do. Thanks for all the
suggestions you guys sent my way. It helps a lot in learning this
stuff.
-Brad
myPanLeft is the outlet to the button and panCounter is an int
declared in the .h file.
- (void)awakeFromNib
{
[myPanLeft setContinuous:YES];
[myPanLeft setState:NSOnState];
panCounter = 0;
}
- (IBAction)panLeft:(id)sender
{
if ([sender state] == NSOnState) {
if (panCounter == 0) {
NSLog (@"Button pressed down");
panCounter ++;
}
}
if ([sender state] == NSOffState) {
NSLog (@"Button released");
panCounter = 0;
[myPanLeft setState:NSOnState];
}
}
On Feb 9, 2007, at 10:33 AM, Shawn Erickson wrote:
> 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
--------------------------------------------------------------
The smime.p7s file below is my public encryption key, not a virus.
More information about the MacOSX-dev
mailing list