Best way to capture key events in NSTextView?

Question :

Best way to capture key events in NSTextView?,

Answer :

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?

,

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.

Read More  Is it possible to unit test a class that makes P/Invoke calls?

So, to detect a key press in a text view, make sure your controller is the text view’s delegate, and then implement this:

- (void)keyUp:(NSEvent *)theEvent  

Note that this is an inherited NSResponder method, not a NSTextView method.

That’s the answer Best way to capture key events in NSTextView?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  Automated processing of an Email in Java