• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: two quick questions: keychain and events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: two quick questions: keychain and events


  • Subject: Re: two quick questions: keychain and events
  • From: Brian Webster <email@hidden>
  • Date: Sun, 24 Jun 2001 19:23:15 -0500

On Sunday, June 24, 2001, at 03:30 PM, cocoa-dev-
email@hidden wrote:

2. Is there any way I can know if any events have taken place in my
app? I want to pop up an alert if there's been no activity (in my
app only) after a certain amount of time.

I think the easiest way to go about this would actually be to subclass NSApplication and override the sendEvent: method that gets called each time an event is sent. So you make a subclass and then specify the name of that class in the NSPrincipalClass key of your Info.plist for the app so AppKit will use your subclass instead of NSApplication. You can set an NSTimer to go off after however much inactivity you want and simply reset it each time an event occurs. It'd look something like this:

@interface MyAppSubclass : NSApplication
{
NSTimer *inactivityTimer;
}

@end

@implementation MyAppSubclass

-(void)sendEvent:(NSEvent*)event
{
[inactivityTimer invalidate];
[inactivityTimer release];
inactivityTimer = [[NSTimer scheduledTimerWithTimeInterval:30.0 target:whateverObjectYouWant selector:@selector(alertUserToStayBusy:) userInfo:nil repeats:NO] retain];
[super sendEvent:event]; //important!
}

@end

You can also test to see if you're in the foreground, filter out mouse move events, etc. before deciding to reset the timer.

Also, it would be helpful
if I could do this not just after the app launched but anytime during
the execution of my program.

Just override -applicationDidFinishLaunching in your app's delegate to set up the timer for the first time.

--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster


  • Prev by Date: NSOutlineView --> NSTextView
  • Next by Date: Another dummy C question
  • Previous by thread: Re: two quick questions: keychain and events
  • Next by thread: PB widget
  • Index(es):
    • Date
    • Thread