Taking over the Command Key
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.