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 > event handling

event handling
Thread Tools
Junior Member
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 13, 2001, 03:06 PM
 
Ok, i want to make a NSTextView for an NSScrollView that has special behavior on a keyDown event. To do this, I subclassed NSTextView and put in these three messages:

Code:
//factory method + (MyTextView *) myTextViewFromNSTextView NSTextView *) tv { return (MyTextView *) tv; } - (void) keyDown NSEvent *) e { [[[self window] delegate] keyPressed:[theEvent characters]]; } - (BOOL) acceptsFirstResponder {return true;} - (BOOL) resignFirstResponder {return false;}
but, when i type a key in the window, which should trigger the keyDown event, the method is not called, I even checked in the debugger and nothing happens.

-Max
     
ali
Forum Regular
Join Date: Sep 2000
Status: Offline
Reply With Quote
Mar 13, 2001, 04:49 PM
 
Is the text object first responder? That is, does it have a blinking cursor? You do this either by clicking it the text view (obviously), or by [[view window] makeFirstResponder:view];

Are you sure you have your own text view in the view hierarchy?

A somewhat unrelated note: keyDown: is fairly low-level in that it lets you see all key events, but will make it hard for you to do proper text processing. Another option is to override insertText:, which is called after input-management (typing Japanese, for instance) and other processing has been done. Which one is more appropriate depends on what you're trying to do.

Ali

     
Junior Member
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 13, 2001, 07:40 PM
 
ali, thank you, you're great.

next question, is there a way to make an NSTextField send an even to its target on every keystroke, not just a return?

-max
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Mar 16, 2001, 08:35 AM
 
I am not sure about this (I am not at home right now to test it) but I seem to recall that being an attribute you can set with IB directly. I am really not sure, though. If not, check the reference on Apple's site because I am almost positive that there was something built-in to handle that case.

Don't kill me if I am wrong, however, I have never actually done much with NSTextField.
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Mar 16, 2001, 10:52 AM
 
Originally posted by mxcantor:
next question, is there a way to make an NSTextField send an even to its target on every keystroke, not just a return?
To send its action on every keystroke? I don't think there's a way directly, but you could implement the controlTextDidChange: delegate method (or listen for the NSControlTextDidChangeNotification on the desired NSTextField).

BTW, YES and NO are the values typically used for BOOL variables (as opposed to true and false, though obviously they'll work too as they're just different names for 1 and 0).
Also, overriding -resignFirstResponder to return NO (or false) is not a good idea at all unless you're just testing, as it will prevent you from moving the cursor out of the textview (or pressing other buttons in the window, etc).

     
   
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:42 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2