Re: catching an option-return
Re: catching an option-return
- Subject: Re: catching an option-return
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 18 Jul 2001 06:15:30 -0400
on 7/18/01 12:22 AM, Dan Watson at email@hidden wrote:
>
I have an NSTextField that sends its action only on enter. unfortunately, it
>
does not send it's action on an option-return, and I need to see if the
>
option key is down when return is hit. anyone know a workaround?
Here's one idea, useful if you want to do something with the text in the
text field.
You can detect when a key is pressed in a text field by subsclassing
NSFormatter and attaching your formatter object to the text field. Override
this method:
-
(BOOL)isPartialStringValid:proposedSelectedRange:originalString:originalSele
ctedRange:errorDescription:r
Then, in the body of the method, start with a statement something like the
following:
if ([[[NSApp currentEvent] characters] characterAtIndex:0] ==
NSCarriageReturnCharacter) {
The NSCarriageReturnCharacter constant is in NSText.h
To detect the Option key you have to look at NSEvent.h, which contains the
characters method, as well as the modifierFlags method and constants to use
with it to detect various combinations of modifier keys. Look at the NSEvent
reference document for details.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
The AppleScript Sourcebook - www.AppleScriptSourcebook.com
Vermont Recipes - www.stepwise.com/Articles/VermontRecipes