• 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: Detecting the Enter Key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting the Enter Key


  • Subject: Re: Detecting the Enter Key
  • From: Alex Heinz <email@hidden>
  • Date: Wed, 10 Dec 2008 14:58:29 -0500


On Dec 10, 2008, at 2:39 PM, Eric Gorr wrote:


On Dec 10, 2008, at 2:28 PM, Michael Ash wrote:

On Wed, Dec 10, 2008 at 12:43 PM, Eric Gorr <email@hidden> wrote:
One way to check to see if the enter key has been pressed is to:

[theEvent keyCode] == 0x04C

where 0x04C is the keyCode corresponding to the enter key.
(Is there an Apple defined constant for this key code?)



Another way, found at:

http://developer.apple.com/samplecode/TrackBall/listing9.html

is to do:

NSString *characters = [theEvent characters];

switch ([characters characterAtIndex:0])
{
 case NSEnterCharacter:
 case NSNewlineCharacter:
 case NSCarriageReturnCharacter:
}



My question is which method is the preferred or recommended way to detect
this key in onKeyDown?


Is there a better way?

It really depends on whether you want to detect the physical key or the logical key.

I am not sure if I understand the difference. Can you expand on this?

The "physical" key means (roughly) the switch on the keyboard that sends an electrical signal with the code 0x04C, which might not necessarily correspond to a key marked "enter" on all keyboards. The logical key is the action performed by that signal, in this case, a line break.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Detecting the Enter Key (From: Eric Gorr <email@hidden>)
 >Re: Detecting the Enter Key (From: "Michael Ash" <email@hidden>)
 >Re: Detecting the Enter Key (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: Detecting the Enter Key
  • Next by Date: Re: Table view containing cells with both an image and text
  • Previous by thread: Re: Detecting the Enter Key
  • Next by thread: Distributing apps
  • Index(es):
    • Date
    • Thread