Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: space bar keyboard short cut
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: space bar keyboard short cut



Nick, thanks a lot for your code sample. I had used a subclass of NSWindow to get the space bar to send an action, but your example is much better. However, whenever I pressed the space bar, I'd get a system beep. I finally figured out that by adding the two 'else' clauses (see below), the beep stops. I *think* the first else clause for the nested 'if' passes key events to the super class, and the second one passes all other events to the super class. If you just have the second one, cmd-Q (and other menu keyboard shortcuts) don't work.

I guess I'm posting this for the benefit of other people like me -- hobbyist programmers.

Thanks again.

Ron Fleckner

nick briggs <email@hidden> wrote:

Karim

You must subclass NSApplication and overide  sendEvent, see below,

In Xcode Targets -> Properties tab,  enter your subclass name under
PrincipalClass

Obviously something inyour responder chain must implement
__SOME_SELECTOR__

----------------------------

@implementation MyApplication


- (void)sendEvent:(NSEvent *)event { if ([event type] == NSKeyDown) { NSString *str = [event characters]; if([str characterAtIndex:0] == 0x20) // spacebar { [super sendAction:@selector(__SOME_SELECTOR__:) to:nil from:self]; }
		  else                            // added this
			[super sendEvent:event];	 //

}
else // and this
    	 [super sendEvent:event];
}

@end

----------------------------

Nick


Message: 2
Date: Sun, 25 Jun 2006 14:04:35 +0200
From: Karim Morsy <email@hidden>
Subject: space bar keyboard short cut
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

hi,

I would like to assign the space (" ") key equivalent for a button
(like in itunes).
how can that be done ?

thanks,
Karim

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.