 |
 |
event handling
|
 |
|
 |
|
Junior Member
Join Date: Nov 2000
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
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).
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

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