On Mar 15, 2012, at 11:53 PM, Peter Zegelin wrote:
> I need to implement something akin to the iTunes Fast Forward or Rewind
> buttons, where a quick mouse click has a different action to when the button
> is pressed for a longer time. I also need to link this action to a short or
> long press of an arrow key on the keyboard. Before I have a go myself does
> anyone know of an example out there?
>
> I am fairly sure I can implement the mouse click part myself but am not
> really sure how to go about adding keyboard support. Any ideas?
Assuming you need the "long" action to be repeated at regular intervals, here's
something I slapped together for you to start with:
- (void)mouseDown:(NSEvent *)event
{
mDownTime = [NSDate timeIntervalSinceReferenceDate];
mDelayForScrubTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self selector:@selector(beginScrubbing:) userInfo:nil repeats:NO];
}
- (void)mouseUp:(NSEvent *)event
{
[mDelayForScrubTimer invalidate];
mDelayForScrubTimer = nil;
[mScrubTimer invalidate];
mScrubTimer = nil;
if ([NSDate timeIntervalSinceReferenceDate] - mDownTime < 0.2) {
NSBeep();
NSLog(@"Jump");
} else {
NSLog(@"End Scrubbing");
}
}
- (void)keyDown:(NSEvent *)event
{
if ([event isARepeat]) return;
<same as mouseDown>
}
- (void)keyUp:(NSEvent *)event
{
<same as mouseUp>
}
- (void)beginScrubbing:(id)timer
{
[mDelayForScrubTimer invalidate];
mDelayForScrubTimer = nil;
mScrubTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
selector:@selector(scrubTimer:) userInfo:nil repeats:YES];
}
- (void)scrubTimer:(id)timer
{
NSBeep();
NSLog(@"Scrub");
}
--
Seth Willits
_______________________________________________
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]