Sadly, that does not work.
performSelector:withObject:afterDelay: will only perform the selector after a
delay after the mouse button goes up. I had actually tried doing this manually
with the code
NSTimer *mouseStillDownTimer = [NSTimer timerWithTimeInterval:1 target:self
selector:@selector(mouseStillDown:) userInfo:NULL repeats:NO];
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
[currentRunLoop addTimer:mouseStillDownTimer forMode:NSDefaultRunLoopMode];
when I first noticed the timers (which performSelector:withObject:afterDelay
relies upon) don't fire until after the mouse button goes up.
I believe this is why there are NSPeriodic events (see the Other Types of
Events section in the Cocoa Event-Handling Guide).
Still, I am not certain how to determine what mouse buttons are down.
The NSEvent methods are either >= 10.6 or for tablets only.
I suppose I could go to Carbon (StillDown?) to get this information, but I was
hoping for a Cocoa based solution.
Thank you.
On Feb 1, 2010, at 4:44 PM, Richard Penwell wrote:
> An alternative technique would be roughly:
>
> 1. Detect mouse down, set state down
> 2. Call performSelectorAfterDelay 1 second with a test method
> 3. If the mouse goes up, set state up
> 4. In the test method, test if the state is down...
>
> On Feb 1, 2010, at 4:42 PM, Eric Gorr wrote:
>
>> What I am trying to accomplish is displaying a menu (perhaps with
>> NSPopUpButtonCell's performClickWithFrame method) after a user clicks on a
>> sublass of NSButton and holds the left mouse button for >= 1 second.
>>
>> Is anyone aware of any sample code doing this?
>>
>> I imagine I will need to customize the mouseDown method of NSButton with a
>> loop that checks to see if the mouse button is still down. However, I am
>> uncertain how to determine this. I have seen NSEvent's pressedMouseButtons
>> method, but it only became available with the 10.6 SDK and I need something
>> that works with 10.5.
>>
>> I am also thinking that I may be taking the wrong approach, so any
>> suggestions on what approach I should be taking would be appreciated.
>>
>> Thank you._______________________________________________
>>
>> Cocoa-dev mailing list ([email protected])
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/almightylinuxgod%40me.com
>>
>> This email sent to [email protected]
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]