xcode newbie: ToolbarSample and keydown events

Discussion in 'Mac Programming' started by Oats, Feb 2, 2007.

  1. Oats macrumors regular

    Jan 8, 2003
    New York
    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:

    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!
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    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.

Share This Page