Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Passing keystrokes to a window...

Passing keystrokes to a window...
Thread Tools
Seamus
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status: Offline
Reply With Quote
Oct 1, 2002, 01:23 PM
 
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
     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Oct 1, 2002, 02:56 PM
 
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.
     
Seamus  (op)
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status: Offline
Reply With Quote
Oct 1, 2002, 03:09 PM
 
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
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Oct 3, 2002, 10:29 AM
 
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.
     
Seamus  (op)
Forum Regular
Join Date: Jul 2002
Location: Los Angeles, CA
Status: Offline
Reply With Quote
Oct 3, 2002, 03:57 PM
 
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
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Oct 4, 2002, 02:58 AM
 
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.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:33 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,