PDA

View Full Version : xcode newbie: ToolbarSample and keydown events




Oats
Feb 3, 2007, 01:28 AM
hello,
i am trying to learn to use xcode and interface builder and all that. i know c++ very well, and know windows programming pretty well. i am having trouble finding out where to start with this xcode stuff.

so i am starting with some sample code and trying to make a simple change.

the ToolbarSample code is here:
http://developer.apple.com/samplecode/ToolbarSample/index.html

is it basically a NSTextView with a simple toolbar.

what I want to do is filter some keydown events, and when "enter" key is hit, insert some text to the NSTextView. do i need to subclass the NSTextView? or do i just need to set up a first responder somehow? how do i catch the key events?

thanks for any help!



robbieduncan
Feb 3, 2007, 03:14 AM
So what has input focus when you want to capture events? The Text View? If that is the case then subclassing that and overriding the various event message handlers would work as long as you passed them on to the superclass.

A slightly cleaner way that will work as long as your window is the key window would be to create a new NSResponder subclass and insert that near the top of the responder chain. If inserted in the correct place you should get key events in that window no matter what control has focus.