• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: catching an option-return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >catching an option-return (From: Dan Watson <email@hidden>)

  • Prev by Date: Re: Creating shared classes
  • Next by Date: Re: Collection of Cocoa & objc questions from a "newbie"
  • Previous by thread: Re: catching an option-return
  • Next by thread: Creating shared classes
  • Index(es):
    • Date
    • Thread