Error beeping problem

Discussion in 'Mac Programming' started by boki46, Dec 30, 2009.

  1. boki46 macrumors newbie

    Dec 30, 2009

    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?

  2. boki46 thread starter macrumors newbie

    Dec 30, 2009
    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.
  3. Sydde macrumors 68020


    Aug 17, 2009
    You do not have to put it into every .m file, only files that are subclasses of NSResponder.

Share This Page