2020-04-03a few seconds read (About 100 words)How to handle enter key in NSTextFieldIssue #635 1textField.delegate = self 123456789101112131415161718192021222324NSTextFieldDelegatefunc control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { if (commandSelector == #selector(NSResponder.insertNewline(_:))) { // Do something against ENTER key print("enter") return true } else if (commandSelector == #selector(NSResponder.deleteForward(_:))) { // Do something against DELETE key return true } else if (commandSelector == #selector(NSResponder.deleteBackward(_:))) { // Do something against BACKSPACE key return true } else if (commandSelector == #selector(NSResponder.insertTab(_:))) { // Do something against TAB key return true } else if (commandSelector == #selector(NSResponder.cancelOperation(_:))) { // Do something against ESCAPE key return true } // return true if the action was handled; otherwise false return false}#swiftmacOS