0
votes

I have a custom NSView in my mac app and I want to do an action when Return key is pressed.

My first attempt was to find the NSResponder action message for this key (like -complete: for ESC key). It seems it is –insertNewline: but it doesn´t work for NSView.

Second one, override -keydown: and check the keyCode of the event. Works but I notice that the keyCode is just the position of a key in the keyboard and differents keyboards (models and languages) will return differents keycodes for Return key (is that correct?).

The last was to subclass my view as NSControl and set the selector to perfom as action (also setting the target) in the -awakeFromNib method of the subclass.

Any of this works. Any idea?

Thanks in advance

1

1 Answers

0
votes

Finally –insertNewline: works perfect. The problem it was that I override keydown using an "if" with "-interpretKeyEvents:" (bad mix when the condition didn´t let perform insertNewline)...