• 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
Taking over the Command Key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Taking over the Command Key


  • Subject: Taking over the Command Key
  • From: Anthony Duer <email@hidden>
  • Date: Sun, 8 Feb 2004 04:23:27 -0800

In an application I'm writing, I need to be able to override Command+Key without using a menu item or an invisible NSButton (it stops responding if something like a NSWindow or NSTextField is in focus). My current idea that I got from checking the archives was to subclass NSApplication and modify sendEvent: as such:

-(void)sendEvent:(NSEvent *) event
{
if(([event type] == NSKeyDown) && ([event modifierFlags] == NSCommandKeyMask))
{
//eventually i'll make this a loop in case more then one char is sent per event
NSString *chars = [event charactersIgnoringModifiers];
char x = [char characterAtIndex: 0];
switch(x)
case 'q': [super sendEvent: event]; //Avoid stepping on NSMenuItem toes
case 'a': [super sendEvent: event];
.
.
.
case 'i': //do something different here
default: //Do what I want here
}
else
[super sendEvent: event];
}

Is this the right way to go about it? Or is there a way to hide a NSMenuItem completely from the user and still have it respond to Command+Key events?

~Anthony Duer
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Anyone have experience coding software updating?
  • Next by Date: applicationShouldTerminateAfterLastWindowClosed
  • Previous by thread: Re: Changing a filename while the FSRef is in use
  • Next by thread: applicationShouldTerminateAfterLastWindowClosed
  • Index(es):
    • Date
    • Thread