tags:

views:

125

answers:

3

Hi All

I want to line break using shift+enter in TextField(Control+Enter is working) I don't want to use TextView because using this Enter Key Action is not performing..

Thanks Deepika

+1  A: 

The standard way to do this is option-return, and it works for free.

Peter Hosey
yes my requirement is shift+enter... like in skype when we type message then shift+enter works
Amit Battan
A: 

Alternatively, if a text view would be more appropriate for your app than a text field, then that's what you should use.

I wrote one that can send action messages. Here's the header and the implementation. It's under a BSD license.

Peter Hosey
It works some time... some time its not works.... when works then work only for 1st time... it works for enter key which is near numeric key....but shit+enter is still issue
Amit Battan
anything which tell us ..is shift key pressed??
Amit Battan
option+enter is not still working in it
Amit Battan
can I use this function for NSTextField , I tried but not able to achieve it.
Amit Battan
It's not a function. It's a subclass of NSTextView that is able to send action message. Such a subclass is unnecessary for NSTextField because NSTextField is already able to send action messages.
Peter Hosey
A: 

Thanks Peter it works I add following in code int flags = [event modifierFlags]; BOOL shift = ( flags & NSShiftKeyMask ) ? YES : NO;

if (([event keyCode] == enterKey1 || [event keyCode] == enterKey2) && !shift) {
    window = [self window];
    [window makeFirstResponder:[window contentView]];

    [NSApp sendAction:action to:target from:self];
}

but now able to set focus on texView after action on textField I was using [textField selecttext];

for TextView I tried [theTextView setSelectedRange: NSMakeRange(0,0)]; but not works

Amit Battan