|
|
Passing keystrokes to a window...
|
|
|
|
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status:
Offline
|
|
Currently my client program has a text view which the users types into and inputs data. I would like the up and down keys to parse through the command history. Unfortunately, keyDown: does not seem to receive any keystrokes that occur when the window is active. Anyone have an idea of what I should do to implement this?
|
I'm a bad...motherf%#!ing DJ
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Have you subclassed the NSTextView instance that you've got in your window? If not, do so and override keyDown: (or moveDown: and moveUp and do whatever you need to do.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status:
Offline
|
|
OK, I created a subclass of ScrollView called "EntryView" and I associated the input field with that class. I also overrode the keyDown function so that it would output all keystrokes to NSLog. However, it still seems to be working as before...any clue?
|
I'm a bad...motherf%#!ing DJ
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
NSScrollView wraps around any other view to provide scrolling behavior (contained as a subview; use the -documentView method to get it). In this case, it's wrapping around an NSTextView. Like smeger said, that is the class you want to subclass, since the NSTextView is getting the keystrokes.
Since NSTextView already passes all keystrokes through the key binding mechanism, your most elegant solution would be override moveUp: and moveDown:, again as smeger said. That way they'll be called whenever the keybinding for "up" and "down" is entered, typically the up and down arrows, plus Control-p and Control-n for those who like Emacs-type bindings. [These bindings are user-settable.]
You could override sendEvent: in an NSWindow subclass to catch the keystrokes earlier. That may be easier for you to do, but it's a more heavy-handed way of doing it.
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status:
Offline
|
|
Lindberg, the problem with subclassing NSTextView is that the interface builder has no way of putting an NSTextView element on the screen. Dragging and dropping NSTextView onto a window creates an NSScrollView, and unchecking "scrollable" does nothing. Since NSTextView is subclassed, I can't select my new class from the CustomClass in the get info. Using the "custom class" element means I can't modify any of the attributes using the interface builder...is this the way to go?
|
I'm a bad...motherf%#!ing DJ
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Yes, a custom view wrapped in a scroll view is the way to go. It's unfortunate you can't then set NSText attributes in IB, but it's usually just a few extra lines of code.
If you get *really* into it, you can make an IB palette that has your NSTextView subclass in it, at which point you could use the IB inspectors to set attributes again (or write your own extended inspector). Being that this a fair bit more work is generally only worth it if you have a subclass that you intend to reuse a number of times.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|