View Full Version : Hide Cursor Again?
Darkroom
Jul 5, 2008, 01:37 PM
the following code will hide the mouse pointer once until the mouse is moved... the problem is that once it's moved, it doesn't disappear again if the view is the same... what method should i call to make it disappear again after say 2 seconds if the view hasn't changed?
-(void)hideMouseOnFullScreenView
{
if ([FullScreenView isVisible])
{
[NSCursor setHiddenUntilMouseMoves:YES];
}
}
kpua
Jul 5, 2008, 02:01 PM
How about just listen for mouseMoved events in your view. Every time the mouse is moved, reset a timer to 2 seconds and make the timer call your -hideMouse... method upon firing.
Darkroom
Jul 5, 2008, 02:29 PM
there's something wrong with my code... totally doing something dumb for sure... coffee is on, but my logic hasn't kicked in yet... so, in my view class i've got this.
- (void)awakeFromNib
{
[self setAcceptsMouseMovedEvents:YES];
}
-(void)mouseMoved:(NSEvent *)event
{
if (timer == nil)
{
NSLog(@"Timer Started / Mouse Moved");
timer = [[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideMouse:) userInfo:nil repeats:NO] retain];
}
else
{
NSLog(@"Timer Ended");
[timer invalidate];
[timer release];
timer = nil;
}
}
-(void)hideMouse:(NSTimer *)timer
{
[NSCursor setHiddenUntilMouseMoves:YES];
}
yoavcs
Jul 5, 2008, 03:47 PM
Your timer is never being allowed to fire. On every mouse move you are reseting it back to 2.0 seconds. Take another look at your timer setting if statement in mouseMoved:
Darkroom
Jul 5, 2008, 03:54 PM
this seems to work:
- (void)awakeFromNib
{
[self setAcceptsMouseMovedEvents:YES];
}
-(void)mouseMoved:(NSEvent *)theEvent
{
NSLog (@"Timer Reset");
[timer invalidate];
NSLog(@"Timer Started");
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideMouse:) userInfo:nil repeats:NO];
}
-(void)hideMouse:(NSTimer *)theTimer
{
[NSCursor setHiddenUntilMouseMoves:YES];
timer = nil;
}
hope my new code isn't dangerous, although i believe it's fine... if anyone can comment on it's safety that would be great...
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.