Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

boki46

macrumors newbie
Original poster
Dec 30, 2009
2
0
Hi,

This is a question for (Cocoa) mac app developers, and gurus.

I've started dabbling in Cocoa, and after building my first application, I'v run into a keyboard key binding issue with OS X:

If a key is not assigned to a menu item in MainMenu.nib, then if it is pressed while the app is running, the computer will beep an error sound (eg. Enter/Return, and 1,2,3,4,etc.).

How do I assign a keyboard key for use in my app, without the need to add it to a menu item (so that OS X doesn't beep, when it is pressed)? Can this be done in Interface Builder, or does it have to be written in Cocoa?

Thanks,
 

boki46

macrumors newbie
Original poster
Dec 30, 2009
2
0
I've found a solution.

For anyone wondering the same question, try placing the following method in the code of one of each .m file, and test if it works:

- (void) keyDown: (NSEvent*) theEvent {}

For me, it was the NSView .m file, that made it work.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
You do not have to put it into every .m file, only files that are subclasses of NSResponder.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.