I'm slowly learning Objective-C and Cocoa, and the only way I see so far to capture key events in Text Views is to use delegation, but I'm having trouble finding useful documentation and examples on how to implement such a solution. Can anyone point me in the right direction or supply some first-hand help?
Objective-c – Best way to capture key events in NSTextView
cocoaeventsobjective c
Related Topic
- Javascript – jQuery Event Keypress: Which key was pressed
- R – Examples of Cocoa/Objective-C and Distributed Objects
- JQuery find events handlers registered with an object
- JQuery multiple events to trigger the same function
- Ios – Xcode – How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X” error
Best Answer
Generally, the way you implement it is simply to add the required function to your view's controller, and set its delegate. For example, if you want code to run when the view loads, you just delegate your view to the controller, and implement the awakeFromNib function.
So, to detect a key press in a text view, make sure your controller is the text view's delegate, and then implement this:
Note that this is an inherited NSResponder method, not a NSTextView method.