<p>How can I dismiss dialog in Cocoa application when user presses Esc or Enter key? I have OK button, is it possible to make it default button?</p>

[{'answer_id': 78110, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 4, 'selected': True, 'text': '<p>If you present the alert panel using the <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAlert_Class/Reference/Reference.html" rel="noreferrer"><code>NSAlert</code></a> class or, <code>NSRunAlertPanel</code> family of functions, or the <code>NSBeginAlertSheet</code> family of functions, you will get support for default and cancel buttons automatically.</p>\n\n<p>If you\'re presenting a sheet that needs OK/Cancel buttons, and you\'re not using any of the above, you should be able to assign your buttons appropriate keyboard equivalents in Interface Builder using the attributes inspector.  (Just highlight the <strong>Key Equiv.</strong> area and press the key you want to be equivalent to pressing that button.)</p>\n\n<p>If you\'re presenting a dialog that\'s not either an alert or a document/window-modal sheet — don\'t. :)  Document-modal alerts aren\'t Mac-like, and shouldn\'t be used for things like preferences windows.</p>\n'}, {'answer_id': 61266602, 'author': 'Kergorian', 'author_id': 2216361, 'author_profile': 'https://Stackoverflow.com/users/2216361', 'pm_score': 0, 'selected': False, 'text': '<p>Just assign the "escapeKey" or "cancelKey" in the IB in the property "key equivalent" for the buttons you want and it will work fine. Also if you assign that keys the buttons gets a different highlighting.</p>\n'}]
['https://Stackoverflow.com/questions/77982', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14131/']